[問題] 資料型別的問題??
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV C++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
NO
問題(Question):
我不太懂運算資料型別的問題
想要練習寫一個找零錢的程式
只寫到要找幾個五百就卡住了QQ
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int a,b,c;--->如果改成int a,b float c會算不出正常值,請問為什麼?
printf("請輸入付款金額\n");
scanf("%d",&a);
printf("請輸入購物金額\n");
scanf("%d",&b);
c=a-b;
c=c/500;
printf("%f\n", c);--->我如果放%d就可以正常算出整數值
system("PAUSE");
return 0;
}
看到書上說的資料轉換的級別
char-->int-->long-->float-->double
所以這個觀念是用在甚麼時候?
可以在printf指定整數給浮點數嗎?或是反之呢?
載運算的時候等號兩邊一定要是同一型的資料嗎?
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.249.218.220
→
05/09 18:27, , 1F
05/09 18:27, 1F
→
05/09 18:46, , 2F
05/09 18:46, 2F
→
05/09 18:49, , 3F
05/09 18:49, 3F
→
05/09 19:47, , 4F
05/09 19:47, 4F
→
05/09 19:47, , 5F
05/09 19:47, 5F
→
05/09 19:48, , 6F
05/09 19:48, 6F
→
05/09 19:48, , 7F
05/09 19:48, 7F
推
05/09 19:49, , 8F
05/09 19:49, 8F
→
05/09 19:49, , 9F
05/09 19:49, 9F
→
05/09 19:50, , 10F
05/09 19:50, 10F
→
05/09 22:25, , 11F
05/09 22:25, 11F
→
05/10 00:00, , 12F
05/10 00:00, 12F
→
05/10 00:01, , 13F
05/10 00:01, 13F
→
05/10 00:02, , 14F
05/10 00:02, 14F
→
05/10 00:03, , 15F
05/10 00:03, 15F
→
05/10 00:04, , 16F
05/10 00:04, 16F
→
05/10 10:56, , 17F
05/10 10:56, 17F
→
05/10 10:57, , 18F
05/10 10:57, 18F
→
05/10 11:00, , 19F
05/10 11:00, 19F