为什么候机楼上写着;二进制表达式“的操作数无效”;?C
这是终端发出的错误:为什么候机楼上写着;二进制表达式“的操作数无效”;?C,c,cs50,C,Cs50,这是终端发出的错误: 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>
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);
}
#包括
#包括
#包括
内部主(空)
{
浮动x;
浮动y=0;
浮动q=25.0;
浮点数d=10.0;
浮点数n=5.0;
浮动p=1.0;
printf(“我欠你多少?在这里输入:”);
x=GetFloat();
while(x25.0)
{
浮动x=x%q;
y++;
}
printf(“使用的%f和硬币的模数:%f\n”,x,y);
}
我认为您熟悉CS50“贪婪”任务。我需要得到剩余的
x
。也许我遗漏了教程中的一些内容,但我认为他们没有指定如何使用模%
运算符 模运算符仅适用于整数类型。您想使用该函数。我认为%
模运算符在浮点
s上不起作用。您可能需要查看fmod()
。