Reputation: 11
can someone help me out? i the only thing wrong is i cant add cost1,cost2, and cost3 up at the end to print out my total from the three items. i get the above error.
#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);
}
Upvotes: 0
Views: 1004
Reputation: 50180
Your mistake is declaring the cost variables as arrays. Not needed.
float cost1[100];
float cost2[100];
float cost3[100];
float total[300];
should be
float cost1;
float cost2;
float cost3;
float total;
Upvotes: 4