Hey guys
I got the this program to do what I want but it doesn't loop until 'Q' is entered. I am just not understanding this, can someone tell me why this doesn't loop?
Thanks
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
// Declare variables
float sales = 0.0;
float trateDelmar = .0725;
float trateEncinitas = .0750;
float trateLajolla = .0775;
float staxDelmar = 0.0;
float totamtDelmar = 0.0;
float staxEncinitas = 0.0;
float totamtEncinitas = 0.0;
float staxLajolla = 0.0;
float totamtLajolla = 0.0;
char input[10];
char selection;
// Program header
printf("\nName:\t\t Brandon McHenry\n");
printf("Class:\t\t POS 370\n");
printf("Assignment:\t Workshop 5\n");
printf("--------------------------------\n");
printf("\nTax calculation program for Kudler stores\n");
printf("\nEnter Purchase Amount: ");
// Read the input and assign it to sales
scanf("%s", input);
sales = atof(input);
if(sales <= 0.0)
{
printf("Invalid input\n");
return 1;
}
// Calculating the sales tax and total amount
staxDelmar = trateDelmar * sales;
totamtDelmar = staxDelmar + sales;
staxEncinitas = trateEncinitas * sales;
totamtEncinitas = staxEncinitas + sales;
staxLajolla = trateLajolla * sales;
totamtLajolla = staxLajolla + sales;
// Displaying the store selection menu
// Loop until 'Q' is selected
do
{
printf("\n Store Selection Menu\n");
printf("\t--------------------------\n");
printf("\n\tD) Del Mar\n");
printf("\tE) Encinitas\n");
printf("\tL) LaJolla\n");
printf("\tQ) Quit\n");
printf("\n\tSelect D, E, L, or Q :");
// Read the selection input and display the selected output until Q is selected
scanf("%c", &selection);
if(selection == 'D')
{
printf("\n\tStore name: Del Mar\n");
printf("\tTax rate: %.2f\n", trateDelmar * 100);
printf("\tPurchase amount: %.2f\n", sales);
printf("\tTax amount: %.2f\n", staxDelmar);
printf("\tTotal sale amount: %.2f\n", totamtDelmar);
fflush(stdin);
getch();
}
if(selection == 'E')
{
printf("\n\tStore name: Encinitas\n");
printf("\tTax rate: %.2f\n", trateEncinitas * 100);
printf("\tPurchase amount: %.2f\n", sales);
printf("\tTax amount: %.2f\n", staxEncinitas);
printf("\tTotal sale amount: %.2f\n", totamtEncinitas);
fflush(stdin);
getch();
}
if(selection == 'L')
{
printf("\n\tStore name: LaJolla\n");
printf("\tTax rate: %.2f\n", trateLajolla * 100);
printf("\tPurchase amount: %.2f\n", sales);
printf("\tTax amount: %.2f\n", staxLajolla);
printf("\tTotal sale amount: %.2f\n", totamtLajolla);
fflush(stdin);
getch();
}
}
while(selection == 'Q');
return 0;
}
// End of program