【发布时间】:2016-12-12 22:56:27
【问题描述】:
这不是我的全部代码,但我不断收到此错误:二进制表达式的操作数无效。
printf("How much change is owed?\n");
float change= GetFloat();
float roundf(float change);
change*=100;
int rem;
while (change>0)
{
if(change>=0.25)
rem=change % 0.25; > error, saying that this is a double????
}
printf ("%d\n", rem); I need the modulo , it is not working
return 0;
【问题讨论】:
-
使用 fmod(a, b) 代替。
-
乘以 100 并四舍五入后,您应该能够使用整数数学和整数变量编写程序的其余部分。
-
嗯,如果
change > 0.0那么while (change>0) { if(change>=0.25) rem=whatever; }看起来像一个无限循环。 -
如果您需要精确算术结果,请不要使用浮点数。