我已经创建了一个类似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