I'm trying to write a program that asks for the flavor of a specific scoop of ice cream and adding it to a total price variable in C. Here's what I have: (Note: Sf
and S
are int
variables, price
is a float
variable, and F
is a char
variable)
#include <stdio.h>
void main(void)
{
float price;
char F;
int S;
int Sf = 1;
int T = 0;
printf("\nHow many scoops do you want? You can choose 1 to 10 scoops\n");
scanf("%d", &S);
printf("\nHere are your flavor options: Vanilla (V) Chocolate (C) Strawberry (S) Oreo (O) Butter Pecan (B)");
while (Sf <= S)
{
printf("\nWhat flavor do you want for scoop %d?\n", Sf);
scanf(" %c", &F);
switch (F)
{
case 'V':
{
price = price + 0.70;
break;
}
case 'C':
{
price = price + 0.75;
break;
}
case 'S':
{
price = price + 0.80;
break;
}
case 'O':
{
price = price + 0.85;
break;
}
case 'B':
{
price = price + 0.90;
break;
}
default:
{
}
Sf += 1;
}
}
printf("\n\n%f", price);
}
I don't know what I'm doing wrong, and I'm very new to C. I appreciate any help
Edit: what happens is when I input one of the requested letters, it simply repeats the question until I enter a number. However, it also runs the specific case.