可能重复:
为什么十进制数不能用二进制精确表示?
#include <stdio.h>
int main(void)
{
int temperature, time;
float minutes;
printf("What is the Fahrenheit temperature?\n");
scanf("%d",&temperature);
time = (5 - (temperature - 90) / 5);
minutes = ((5 % time) * 60);
if (temperature >= 90)
printf("It will rain at approximately %d hours and %f minutes after noon.\n", time, minutes);
else
printf("It will not rain today.\n");
system("PAUSE");
return 0;
}
我正在使用 C 编程语言。这是作业,但只要不是整个代码,就可以使用网络上的一些位。无论如何,如果当前温度是 93f time = 4.4
所以我想输出:
It will rain approximately 4 hours and 24 minutes after noon
但输出是:
It will rain at approximately 5 hours and 0.000000 minutes after noon
编辑:我现在收到一个错误,指出二进制 % 的操作数无效(有 int 和 float)请耐心等待我正在尝试学习的 LOL。
#include <stdio.h>
int main(void)
{
int current_temp;
float remaining_minutes, time;
printf("What is the temperature in Fahrenheit?\n");
scanf("%d",¤t_temp);
time = (5 - (current_temp - 90) / 5);
ERROR**** remaining_minutes = ((5 % time) * 60);
if (current_temp >= 90)
printf("It will rain at approximately %d hours and %f minutes after noon.\n", time);
else
printf("It will not rain today.\n");
system("PAUSE");
return 0;
}