I want to ask the user how many tickets he wants to buy and then have a loop that will specify what type of ticket he wants. Each kind of ticket has a different value and I want to calculate the total sum of the tickets. The problem is that for some reason it iterates in a weird way. Why is that? I tried with a for loop as well and an array of chars but the results were the same. What am I missing here?
#include <stdio.h>
#include <stdbool.h>
int main()
{
int n,i;
printf("How many tickets would you like?\n");
scanf("%d", &n);
char c;
float sum = 0;
while(n)
{
printf("What type of ticket do you want?\n");
scanf("%c",&c);
switch (c)
{
case ('E'):
{
sum +=0.23;
break;
}
case('A'):
{
sum+=0.7;
break;
}
case('T'):
{
sum+=0.15;
break;
}
}
n--;
}
printf("Sum is: %f", sum);
return 0;
}