这是终端发出的错误:
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&#34;贪婪&#34;任务。我需要得到x
的剩余部分。也许我在教程中遗漏了一些内容,但我认为他们没有指定如何使用模%
运算符。