I have some problem with my homework. So this is how it looks like
#include<stdio.h>
int main()
{
char code;
int price,discount;
float total;
printf("Please input price: ");
scanf("%d",&price);
printf("Please input discount code: ");
scanf(" %c",&code);
switch(code)
{
case 'a': printf("Your discount code is 25 percent\n");
discount = 25;
break;
case 'b': printf("Your discount code is 15 percent\n");
discount = 15;
break;
case 'c': printf("Your discount code is 5 percent\n");
discount = 5;
break;
default: printf("Wrong code,Your discount is 0 percent\n");
discount = 0;
break;
}
total = (price*((100-discount)/100));
printf("Your price is = %.2f\n",total);
}
I have 2 questions to ask
My task is I have to input both of uppercase and lowercase letter for discount code (there are only three codes: a, b, c) so how can I put both of them in case command? (in this I only do the lowercase letter)
I have run this. But it seems like the discount value is 0 when I try to used it for calculate in the end. When I print the discount only, it works normally. How can I fix that?
Sorry for my poor English and Thank you for your help!