cpp
/*Angel0430
Service Request: SR-kf-008
Change Request Number 2
Modify the C program so that the user inputs the purchase amount
Check the user's input for validity
Have user select from a menu which store to use for the tax calculation
Calculate and display the tax amount for the store selected and the total sale amount for that store
*/
// user selects amount of purchase
#include <stdio.h>
/*Using define macros for assigning tax to different stores */
#define DelMar 7.25
#define Encinitas 7.5
#define LaJolla 7.75
/*
Input:
o Del Mar - 7.25%
o Encinitas - 7.5%
o La Jolla - 7.75%
Output:
The sales tax amount for store selected by user for an amount selected by user
*/
float user_input(){
float amount;
printf("Please Enter the sales amount\n");
scanf("%f", &amount);
return amount;
}
int displayMenu(){
int choice;
printf("1. Del Mar - (7.25%%)\n");
printf("2. Encinitas - (7.5%%)\n");
printf("3. La Jolla - (7.75%%)\n");
printf("\n\nSelect a store for tax calculation [1-3]:");
scanf("%d",&choice);
return choice;
}
int main(){
// The total sales for each store is
float sales = user_input();
int storenum;
sales = user_input();
if (sales < 0.0) {
printf("Error! Sales cannot be negative");
exit(-1);
}
storenum = displayMenu();
//Display Program Header
printf("Tax Calculator for Kudler Fine Foods for All 3 locations\n\n\n");
printf("STORE LOCATION\tSALES AMOUNT\tTAX RATE\tTAX AMOUNT\n");
printf("==============\t============\t========\t==========\n");
printf("==============\t============\t========\t==========\n");
switch (storenum){
case 1:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Del Mar
printf("Del Mar \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, DelMar, sales*DelMar/100);
break;
case 2:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for Encinitas
printf("Encinitas\t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, Encinitas, sales*Encinitas/100);
break;
case 3:
//Calculate and print the store location, Sales, Tax rate, and Tax amnt for La Jolla
printf("La Jolla \t$%.2f\t\t%.2f%%\t\t%.2f%\t\n",sales, LaJolla, sales*LaJolla/100);
break;
} //Switch ends
printf("================================================================\n");
printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
printf(" Press ENTER to Exit Program and Have A Nice Day \n");
printf(" +++++++++++++++++++++++++++++++++++++++++++++++++\n");
getch();
return 0;
}
This is the response to compiling:
Miracle C Compiler (r3.2), written by bts.
Compiling c:\documents and settings\user\my documents\dar\uop\pos 370\week 4\week 4 individual service request 2.c
user_input
displayMenu
main
1% cg space used
Time taken: 0.156 seconds
This is the response to the build:
Miracle C Compiler (r3.2), written by bts.
Compiling c:\documents and settings\user\my documents\dar\uop\pos 370\week 4\week 4 individual service request 2.c
user_input
displayMenu
main
1% cg space used
Time taken: 0.047 seconds
Linking object c:\documents and settings\user\my documents\dar\uop\pos 370\week 4\week 4 individual service request 2.obj,,c:\documents and settings\user\my documents\dar\uop\pos 370\week 4\week 4 individual service request 2.map,c:\Program Files\Miracle C\ccl.lib ;
Build completed
Now when I execute, I get a "Execute Program" window asks for Optional Parameters [don't know what to put in there], then run, cancel or help are the options. I have been executing it without placing anything in the Optional Parameters window. Remarkably, this time when I executed I got a window that prompted me to "Please enter sales amount" -- I put any number ($200.00) and pressed enter -- I get the following:
1. Del Mar - (7.25%)
2. Encinitas - (7.5%)
3. La Jolla - (7.75%)
Select a store for tax calculation [1-3]:Tax Calulator for Kudler Fine Foods for All 3 locations
STORE LOCATION SALES AMOUNT TAX RATE TAX AMOUNT
================ ============== ========= ============
================ ============== ========= ============
+++++++++++++++++++++++++++++++++++++++++++++++++
Press ENTER to Exit Program and Have A Nice Day
+++++++++++++++++++++++++++++++++++++++++++++++++
When I pressed a store selection the window dropped off. Why?
Mod edit: Please
Thanks, gabehabe