-1

重複の可能性:
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",&current_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;



}
4

4 に答える 4

0

分 = (時間 % 1) * 60 はどうですか?

編集: or mins = (time*10 % 10) * 6.私の電話では、実際にはテストできません。

于 2012-10-11T20:08:10.130 に答える
0

timeですint。浮動小数点数を保持することは期待できません。

于 2012-10-11T20:08:19.870 に答える
0

時間も定義する必要がありますfloat。現在、整数を整数で除算しているため、整数のみが得られます。

于 2012-10-11T20:07:04.283 に答える