Im trying to solve this problem:
"Make a program in C (not in C++) that calculates the tax of a
product. The user will introduce the price of the product. If the
product is medicine, the program will add a 0% tax. If the product
is school supply, the program will add a 10% tax. And for any other
case, the program will add a 16% tax.
You are only allowed to use: <stdio.h>"
My attempt is the code:
#include <stdio.h>
int main()
{//declare variables required
float price,tax=0;
char ch;
//reaf price and product type
printf("Enter price:");
scanf("%f",&price);
printf("select product
type:\nm-medicine\ns-schoolsupply\no-others");
printf("\nchoose:");
scanf("%c",&ch);
if(ch=='m')//based on type calculate
//tax and display appropriate message
printf("\nNo tax on medicines");
if(ch=='s'){
printf("\nproduct is for school");
tax=price*0.10;
printf("\ntax will be of %f ",tax);
}
else if(ch=='o'){
printf("\nproduct is for other purpose");
tax=price*0.16;
printf("\ntax will be %f",tax);
}
return 0;
}
But when I try to type "m", "s" or "o" to choose the type of
product the program tells me that it cant find the order "m" (or
"s" or "o"). Can you tell me whats wrong with my code?
Im trying to solve this problem: "Make a program in C (not in C++) that calculates the tax of a product. The user will i
-
- Posts: 43759
- Joined: Sat Aug 07, 2021 7:38 am