可能重複:
Why can’t decimal numbers be represented exactly in binary?在C語言中使用mod輸出分鐘需要幫助?
#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;
}
** ** INT溫度,時間。 – m0skit0