Can anyone tell me why my program ends if the user inputs an alpha instead starting the loop again?
thanks
Code:
#include <stdio.h>
#include <cstdio>
#include <iostream>
main()
{
// variables
int iResponse, validate;
float purchaseAmount, tax = 0.0;
float delMarTaxRate=.0725;
float encinitasTaxRate=.075;
float laJollaTaxRate=.0775;
char option = 'Y';
// Menu Selection
do // loop for repeating process
{ printf("\n\t\tStore Location\n");
printf("\n\t1\tDel Mar\n");
printf("\t2\tEncinitas\n");
printf("\t3\tLa Jolla\n");
printf("\nPlease select a location: ");
scanf("%d", &iResponse);
//switch for store location
switch (iResponse)
{
case 1:
printf("\nYou selected Del Mar\n\n");
break;
case 2:
printf("You selected Encinitas\n\n");
break;
case 3:
printf("You selected La Jolla\n\n");
break;
default:
printf("Invalid selection\n\n");
goto skip_point;
} //end switch
// Input sale amount
printf("\tEnter Purchase Amount: ");
validate =scanf("%f", &purchaseAmount);
if (validate!=0);
else goto skip_point;
// Display tax and total sale amount
if(iResponse==1)
{ printf("\n\tThe tax amount for Del Mar is $%.2f\t",
tax = (purchaseAmount*delMarTaxRate));
printf("\n\tThe total sale amount for Del Mar is $%.2f\t\n",
purchaseAmount + (tax + .005));
}
if(iResponse==2)
{ printf("\n\tThe tax amount for Encinitas is $%.2f\t",
tax =(purchaseAmount*encinitasTaxRate));
printf("\n\tThe total sale amount for Encinitas is $%.2f\t\n",
purchaseAmount + tax );
}
if(iResponse==3)
{ printf("\n\tThe tax amount for La Jolla is $%.2f\t",
tax = (purchaseAmount*laJollaTaxRate));
printf("\n\tThe total sale amount for La Jolla is $%.2f\t\n",
purchaseAmount + (tax + .005));
}
skip_point:
if (validate==0)
{
printf("\nInvalid purchase amount\n\n");
printf("\nTry again? Y/N\t");
scanf("%c",&option);
}
}
while (option == 'y' || option == 'Y');
printf("\nPress any key to terminate program");
getch();
}