我正在學習c,這是本書'Head First C'中的練習,我的代碼看起來與示例相同,但是我收到了上述錯誤。'無效的操作數到二進制==(有'數量'和'INT')'是什麼意思?
#include <stdio.h>
typedef enum {
COUNT,POUNDS,PINTS
}unit_of_measure;
typedef union {
short count;
float weight;
float volume;
}quantity;
typedef struct{
const char *name;
const char *country;
quantity amount;
unit_of_measure units;
}fruit_order;
void display(fruit_order order)
{
printf("The order contains ");
if(order.amount==PINTS) //ERROR HERE
printf("%2.2f pints of %s\n",order.amount.weight, order.name);
else if(order.amount==POUNDS){ //ERROR HERE
printf("%2.2f lbss of %s\n",order.amount.weight, order.name);
else
printf("%i %s\n",order.amount.weight, order.name);
}
int main()
{
fruit_order apples = {"apples","Canada", .amount.count=100, COUNT};
fruit_order strawberries = {"strawberries","England", .amount.count=100, PINTS};
fruit_order oj = {"juice","USA", .amount.count=100, PINTS};
display(apples);
display(strawberries);
display(oj);
return 0;
}
這個錯誤是什麼意思?
哈哈感謝。我不敢相信我做到了。 – RapsFan1981