-2

これは端末が出すエラーです:

greedy.c:26:21: error: invalid operands to binary expression
      ('float' and 'float')
        float x = x % q;
                  ~ ^ ~
1 error generated.

次のコードから:

#include <stdio.h>
#include <cs50.h>
#include <math.h>

int main(void) 
{
    float x;
    float y = 0;
    float q = 25.0;
    float d = 10.0;
    float n = 5.0;
    float p = 1.0;

    printf("How much I owe you? Enter here: ");

    x = GetFloat();

    while (x <= 0)
    {
        printf("Please enter the sum with a decimal point (e.g. .50; 1.37): ");
        x = GetFloat();
    } 

    if (x > 25.0) 
    {
        float x = x % q;
        y++;
    }

    printf("The modulo of %f and the coins used: %f\n", x, y);

}

CS50の「貪欲な」タスクについてはご存知だと思います。の残りを取得する必要がありxます。%チュートリアルで何かを見逃したのかもしれませんが、モジュロ演算子の使用方法が指定されていなかったと思います。

4

1 に答える 1