i am trying to build a small program that uses the input from the user, and then uses a switch case to perform an action that fits the user input. i have been tring to find what is wrong in my program, with no luck. there is clearly something i am missing.
here is the code, can you help me find what is wrong with it?
#include <stdio.h>
#define A 8.5
#define B 7.6
#define C 7.7
#define D 7.7
int main ()
{
char fuel;
float amount,total;
printf("please enter the desired fuel\n");
scanf_s("%c",&fuel);
switch(fuel)
{
case 'A' :
printf("how many liters of fuel do you want?\n");
scanf_s("%f",&amount);
total=amount*A;
if(total>150)
{
printf("the total price to pay is %.3f: \nYou have won a newspaper", total);
}
else
printf("the total price to pay is %.3f", total);
break;
case 'B' :
printf("how many liters of fuel do you want?\n");
scanf_s("%f",&amount);
total=amount*B;
if(total>150)
printf("the total price to pay is %f: \nYou have won a newspaper", total);
else
printf("the total price to pay is %.3f", total);
break;
case 'C' :
printf("how many liters of fuel do you want?\n");
scanf_s("%f",&amount);
total=amount*C;
if(total>150)
printf("the total price to pay is %f: \nYou have won a newspaper", total);
else
printf("the total price to pay is %.3f", total);
break;
case 'D' :
printf("how many liters of fuel do you want?\n");
scanf_s("%f",&amount);
total=amount*D;
if(total>150)
printf("the total price to pay is %f: \nYou have won a newspaper", total);
else
printf("the total price to pay is %f", total);
break;
default:
printf("no\n");
break;
}
}
Even when i input 'A', 'B', 'C' or 'D' it goes to the default, and not to the apropriate case. thanks for the help.