#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, itemAmount, totalFee = 0, rate[10], fee[6] = {7, 3, 5, 2, 3};
char item[6][50], inputItem[50];
strcpy(item[0], "Rice Cooker");
strcpy(item[1], "Radio");
strcpy(item[2], "Iron");
strcpy(item[3], "Charger");
strcpy(item[4], "Kettle");
printf("Amount of item: ");
scanf("%i", &itemAmount);
for(int a = 0; a < itemAmount; a++){
printf("\n%i) Item : ", a+1);
scanf("%s", &inputItem);
strcpy(item[a], inputItem);
if(item[a] == item[0]){
rate[a] = fee[0];
}else if(item[a] == item[1]){
rate[a] = fee[1];
}else if(item[a] == item[2]){
rate[a] = fee[2];
}else if(item[a] == item[3]){
rate[a] = fee[3];
}else{
rate[a] = fee[4];
}
totalFee = totalFee + rate[a];
}
printf("\n%i", totalFee);
}
I want to add all of the items' rate at the end but when I run it, all of the items's rate are 7 instead of the following:
Rice Cooker: 7
Radio: 3
Iron: 5
Charger: 2
Kettle: 3
For example, if I enter two items, which are Radio and Kettle, the total rate went to 10. It is wrong because the radio(3) and kettle(3), should be 6 if they're added up.
I'm now learning array and I'm very new to programming please help me :)