我正在尝试编写一个程序来计算变化,但它似乎并没有起作用。 我认为问题是欠1 /付1;当我试图在那里打印时,我什么都没得到(0)。 有什么帮助吗?
#include <stdio.h>
int main()
{
double owed, paid;
int dollars, quarters, dimes, nickels, cents, remainder, owed1, paid1;
printf("how much did the customer have to pay ?\n");
scanf("%f",&owed);
printf("how much did the customer pay ?\n");
scanf("%f",&paid);
owed1 = owed * 100;
paid1 = paid * 100;
int change = paid1 - owed1;
dollars = change / 100;
remainder = change % 100;
quarters = remainder / 25;
remainder = remainder % 25;
dimes = remainder / 10;
remainder = remainder % 10;
nickels = remainder / 5;
remainder = remainder % 5;
cents = remainder;
printf("%d",dollars);
printf("Dollars:%d, Quarters:%d, Dimes:%d, Nickels:%d, Cents:%d", dollars , quarters , dimes , nickels , cents );
return 0;
}
答案 0 :(得分:0)
您在scanf中使用%f
,它是浮点数的格式说明符,但您的变量是双精度数。您应该使用%lf
代替:
scanf("%lf",&owed);
paid
也是如此。您应该收到编译器的警告。