Hi, I was wondering if anyone could offer an insight into why my piece of code isn't working.
Code:
#include <stdio.h>
//This includes the standard input output library.
main ()
{
float price, VAT, price_plus_VAT, VATD;
char a, new_VAT;
//This defines the variables 'price' and 'VAT' as floating integer. I chose floating integers because the 'price' and 'VAT' will most likely
//require a decimal place.
start:
printf("\nWould you like to enter a new value for the VAT? (Y/N):\n");
new_VAT=getchar();
if(new_VAT=='Y')
{
printf("\nPlease enter the new value for VAT:");
scanf("%f",&VAT);
VATD=VAT/100;
}
else
{
VAT=17.5;
VATD=VAT/100;
}
printf("\nPlease enter a price to calculate the VAT off:");
//This prints text prompting the office worker to enter a price.
scanf("%f",&price);
//This scans for the value entered by the office worker and stores it in the variable 'price'.
price_plus_VAT=price+price*VATD;
printf("The price you entered %.2f\n",price);
printf("The current VAT ammount is %.2f%\n",VAT);
printf("The price including VAT is %.2f\n",price_plus_VAT);
//This prints text telling the office worker what price he entered.
//By default the program displays 5 decimal places which is more than necessary for this program.
//The .2 means only two decimal places will be shown.
printf("Would you like to repeat this program? Y/N");
a=getchar();
if(a=='Y')
goto start;
}
The first IF function works fine, but it just displays the three printf functions displaying information an the "would you like to repeat this program? Y/N" printf (like it should) then quits.
I can't see why it completly ignores the second IF function and the a=getchar();
I've spent hours trying to see if i've missed something.
Can anyone help? It would be greatly appreciated.
Cheers
Whytock