Hey guys, maybe I am just worn out today, but can somebody look at my IF loop (the first one for selcting 1-3) and see where I am going wrong?
Everything else seems to be pretty good I think, but this is aggravating me to no end.
Thanks
#include <stdio.h> // standard input output library
#include <string.h> // basic string handling library added for cAgain option
//Assigns tax value for calculations
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75
char cAgain; //repeat variable for Y/N questions
int displayMenu() // creates menu
{
int choice;
printf("Tax Calculation for $125 Purchase\n\n");
printf("1. Del Mar \n");
printf("2. Encinitas \n");
printf("3. La Jolla \n");
printf("\n\nPlease Select Store for Which to Calculate [1-3]:");
scanf("%d",&choice);
return choice;
}
int main()
{
YES:
{
// Sales value for calculations
float sales = 125.00;
int storenum;
storenum = displayMenu();
if storenum >=1 || if storenum <=3 //While Loop to Request Input of 1,2,or 3, still working on this
{
switch (storenum) // simple switch which responds to corresponding menu choice with output
{
case 1:
//Calculates and Displays Store, Sales, Tax rate, Tax for Del Mar
printf("\nDel Mar \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\t\n\n",sales, DelMar, sales*DelMar/100); //values are correct so I am leaving it this way. ahead of schedule here.
break;
case 2:
//Calculates and Displays Store, Sales, Tax rate, and Tax for Encinitas
printf("\nEncinitas \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\t\n\n",sales, Encinitas, sales*Encinitas/100);
break;
case 3:
//Calculates and Displays Store, Sales, Tax rate, and Tax for La Jolla
printf("\nLa Jolla \tSale $%.2f\tTax %.2f%%\tTax $%.2f%\t\n\n",sales, LaJolla, sales*LaJolla/100);
break;
} //Storenum switch end
}
else
{
fflush(stdin);
printf("\nPlease enter 1,2 or 3\n");
printf("\n\tINVALID NUMBER ENTERED! Would you like to try again? (y/n) ");//allows repeat
scanf("%c", &cAgain); //scan input to repeat program
if (cAgain == 'y' || cAgain == 'Y')//repeats calculator
{
goto YES; //back to menu
}
else if (cAgain == 'n' || cAgain == 'N')//sends to end
return 0;
}
printf("\n\tWould you like to calculate for another store? (y/n) ");//prompts for repeat
scanf("%c", &cAgain);
if (cAgain == 'y'|| cAgain == 'Y')//repeats calculator upper or lower case
{
goto YES; //sends user back to the begining
}
else if (cAgain == 'n' || cAgain == 'N')//ends program upper or lower case
{
printf("\n\tPlease press enter to exit\t\n"); //prompts for exit
}
return 0;
}
}