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