Code:
#include <stdio.h>
int Purchase, TaxRate;
char County;
int main()
{
printf("AMOUNT OF PURCHASE? ");
scanf("%i", &Purchase);
printf("COUNTY? ");
scanf("%c \n", &County);
printf("TOTAL BILL: $ ");
switch(County)
{
case 65:
TaxRate = 7;
Purchase += (Purchase * TaxRate / 100.0);
break;
default:
TaxRate = 6;
Purchase += (Purchase * TaxRate / 100.0);
break;
}
printf("%3.2f", (float) Purchase);
}
this is the current code, I have made changes that people have suggested. I type in 15, A for county, and total bill appears as 15.00. when I type anything for county total bill comes up as 15.00.
I don't think the switch case is working, or if its getting to switch case. I think it is bypassing it for some reason.
thanks
simon
I included,
printf("taxrate is %1 \n", TaxRate);
and it prints,
taxrate is 6
so the switch case is working to some extent. I don't think the "County" thing is working. also, the expression purchase += (purchase etc..) this is not working. otherwise the default value would give a different number at output.
ok latest code
Code:
#include <stdio.h>
float Purchase, TaxRate;
char County;
int main()
{
printf("AMOUNT OF PURCHASE? ");
scanf("%f", &Purchase);
printf("COUNTY? ");
scanf("%c \n", &County);
switch(County)
{
case 65:
TaxRate = 7;
break;
default:
TaxRate = 6;
break;
}
Purchase += (Purchase * TaxRate / 100.0);
printf("taxrate is %1.0f \n", TaxRate);
printf("TOTAL BILL: $ ");
printf("%3.2f", Purchase);
}
this takes and shows input, shows county, shows default taxrate no matter what letter is pressed, shows the correct value of purchase and tax. so the purchase expression is working. the switch case is not.