我已經創建了一個類似ATM的程序,它將錢存在一個人的賬戶中。當該人取出提款時,它會扣除該賬戶的提款以及0.50附加費。我遇到的問題是在這個程序中使用整數和浮點數。我將整數帳戶轉換爲浮點數,但當我嘗試打印出語句時收到錯誤消息。有人能告訴我我做錯了什麼嗎?使用浮點數和整數
#include <stdio.h>
int main (void) {
int account = 2000;
int withdrawal;
float charge = 0.50;
printf ("How much money would you like to take out? ");
scanf ("%i", &withdrawal);
while (withdrawal % 5 != 0) {
printf ("Withdrawal must be divisible by 5. ");
scanf("%i", &withdrawal);
}
account = ((float) account - charge) - withdrawal;
printf("Remaining account: %.2f\n", account);
return 0;
}
我希望通脹保持在足夠低的水平,在我整個一生中,64位就足夠了。 – 2012-01-16 21:27:04