-2
當我嘗試在C中實現「%」運算符而使用float輸入時發生。 我參加了cs50課程,這是我嘗試的問題集1中的第四個問題。以下錯誤消息是什麼意思「錯誤:無效的操作數到二進制表達式('double'和'double')」?
下面的代碼
#include <cs50.h>
#include <stdio.h>
int main(void)
{
printf("O hai! How much change is owed?\n");
float x = get_float();
if(x % 0.25 == 0)
{
printf("%.55f\n", x/0.25);
}
else if(x % 0.10 == 0)
{
printf("%.55f\n", x/0.10);
}
else if(x % 0.05 == 0)
{
printf("%.55f\n", x/0.05);
}
else if(x % 0.01 == 0)
{
printf("%.55f\n", x/0.01);
}
}
我用FMOD代替%,但它給錯誤 「greedy.c:8:10:錯誤:預期 ')' 如果(X FMOD 0.25 == 0)」 ^ – ayushdubey
使用'如果(FMOD(X, 0.25)== 0.0)' – vasek