【发布时间】:2017-07-06 06:53:12
【问题描述】:
有人可以帮帮我吗?我唯一的错误是我不能在最后添加成本 1、成本 2 和成本 3 以打印出这三个项目的总数。我收到上述错误。
#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);
}
【问题讨论】:
-
请记住我是初学者
-
嗨 Derek,欢迎来到 Stack Overflow。您的问题是关于
C语言,而不是标记为C#。这些是完全不同的语言,因此请注意正确标记。也就是说,cjds 已经发布了一个可以解释问题的答案。 -
我的错,我对编程非常陌生
-
它可以帮助您获得更好的答案,并且人们倾向于监控他们最感兴趣的领域,
C#人们不一定会给您最好的答案 @987654325 @ 问题。希望你能找到答案。 -
我已回滚您最近的编辑。您更改了问题中的代码以更正您所询问的问题。这会使任何答案无效并使问题变得无用。请不要那样做。
标签: c