0
有人可以幫我嗎?我唯一錯的是我不能在最後打印出我的總數從三項中增加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);
}
請記住我是一個初學者 –
德里克嗨,歡迎堆棧溢出。你的問題是關於「C」語言,而不是「C#」標記的。這些是完全不同的語言,所以請小心標記正確。也就是說,cjds發佈了一個應該解釋問題的答案。 – Corey
我的不好,我對編程非常陌生 –