重複の可能性:
10 進数を 2 進数で正確に表現できないのはなぜですか?
#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プログラミング言語を使用しています。これは宿題ですが、コード全体ではない限り、Web の一部を使用しても問題ありません。とにかく、現在の温度が 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 を持っている) であることを示すエラーが表示されるようになりました。
#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;
}