错误:二进制+的操作数无效(有'float *'和'float *')

时间:2017-02-16 22:50:37

标签: c

有人可以帮帮我吗?我唯一不对的是我不能在最后添加cost1,cost2和cost3从三个项目中打印出我的总数。我得到了上述错误。

#include <stdio.h>
#include <string.h>

char name1[100];
char name2[100];
char name3[100];
char price1[100];
char price2[100];
char price3[100];
float cost1[100];
float cost2[100];
float cost3[100];
float total[300];

int main()
{
printf("Welcome to the UT super mart*-*-\n");
printf("Enter the name of your item 1: ");
fgets(name1, sizeof(name1), stdin);
printf("Enter the price of %s: ", name1);
fgets(price1, sizeof(price1), stdin);
sscanf(price1, "%f", &cost1);

printf("Enter the name of your item 2: ");
fgets(name2, sizeof(name2), stdin);
printf("Enter the price of %s: ", name2);
fgets(price2, sizeof(price2), stdin);
sscanf(price2, "%f", &cost2);

printf("Enter the name of your item 3: ");
fgets(name3, sizeof(name3), stdin);
printf("Enter the price of %s: ", name3);
fgets(price3, sizeof(price3), stdin);
sscanf(price3, "%f", &cost3);

total=cost1+cost2+cost3; /*this is what causes the error*/
printf("Your total is: %f\nThank you for shopping at the UT super mart.", total);
return(0);
}

1 个答案:

答案 0 :(得分:4)

您的错误是将成本变量声明为数组。不需要。

float cost1[100];
float cost2[100];
float cost3[100];
float total[300];

应该是

float cost1;
float cost2;
float cost3;
float total;