I have to hit <Enter> twice after inputting my dollar amount and store selection
I think I am just missing something simple somewhere, but am going stupid looking for it.
Went to the internet to try and find a good debugger, but have no idea how or where to even begin that process.
any suggestions are welcome
#include <stdio.h> // standard input output library
//defines tax value for calculations
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75
char cAgain; //variable for Y/N questions
float user_input() // week 4 addition for sales amount
{ //prompt, collect, and store sale amount
float fAmount; //defines amount type as float
printf("Enter Amount of Sale $ ");
while ((scanf("%f", &fAmount) != 1) || (fAmount <= 0.0)) //week 5 character validation addition
{
while (getchar() != '\n') {;} // week 5 character validation
printf("PLEASE ENTER POSITIVE DOLLAR AMOUNT:");
}
while (getchar() != '\n') //week 5 character validation
{;}
return fAmount;
}
int iMenu() //defines menu variable
{ // menu which prompts, collects, and stores store number
int iSelection; //defines selection type as integer
printf("Tax Calculation for Purchase\n\n"); //changed to reflect week 4 updates
printf("1. Del Mar \n2. Encinitas \n3. La Jolla\n");
printf("\n\nPlease Select Number of Store for Which to Calculate: ");
scanf("%d", &iSelection);
while (getchar() != '\n') // week 5 character validation
{;}
while (iSelection < 1 || iSelection > 3) //integer validation
{
printf("INVALID NUMBER ENTERED! Please enter 1,2 or 3:");
scanf("%d", &iSelection);
while (getchar() != '\n') //week 5 character validation
{;}
}
return iSelection;
}
int main() //main loop getting shorter an shorter
{
float fSales; // Sales value for calculations
int iStorenum; //defines store for main loop, menu will not work without
do // week 5 do/while loop to replace GOTO and STARTOVER
{
fSales = user_input(); //new week 4 sales total
iStorenum = iMenu(); //displays menu created above
if (iStorenum == 1)
//Calculates and Displays Del Mar Store, Sales, Tax rate, and Tax
printf("\nDel Mar \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= \t$%.2f\t\n\n",fSales, DelMar, fSales*DelMar/100, DelMar*fSales/100+fSales);
if (iStorenum == 2)
//Calculates and Displays Encinitas Store, Sales, Tax rate, and Tax
printf("\nEncinitas \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= \t$%.2f\t\n\n",fSales, Encinitas, fSales*Encinitas/100, Encinitas*fSales/100+fSales);
if (iStorenum == 3)
//Calculates and Displays La Jolla Store, Sales, Tax rate, and Tax
printf("\nLa Jolla \tSale $%.2f\tRate %.2f%%\tTax $%.2f%\tTotal= \t$%.2f\t\n\n",fSales, LaJolla, fSales*LaJolla/100, LaJolla*fSales/100+fSales);
printf("\n\tRun Calculator Again? (y/n) ");//prompts for repeat
scanf("%c", &cAgain);//scans input at store number prompt
} while (cAgain == 'y' || cAgain == 'Y'); // week 5 do/while end
}