Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,359 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,190 people online right now. Registration is fast and FREE... Join Now!




I have comments in the code that describe what went wrong.

 
Reply to this topicStart new topic

I have comments in the code that describe what went wrong., Calculating Sales Tax for Kudler Food Store in 3 Different Tax Regions

angel0430
post 21 Aug, 2008 - 04:23 PM
Post #1


New D.I.C Head

*
Joined: 20 Aug, 2008
Posts: 2

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 code.gif
Thanks, gabehabe smile.gif
User is offlineProfile CardPM

Go to the top of the page

flumer
post 21 Aug, 2008 - 07:17 PM
Post #2


New D.I.C Head

*
Joined: 8 Jun, 2007
Posts: 5


My Contributions


Could I see your program in the last window's image?
I run your program in gcc,but computer don't see c=getchar();
I change your program,but can't make it.
CODE

/*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(void){
// The total sales for each store is
    float sales = user_input();
    char c;
    int storenum;
    if (sales < 0.0) {
        printf("Error! Sales cannot be negative\n");
        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");
    c=getchar();
    return 0;
}
User is offlineProfile CardPM

Go to the top of the page

jacobjordan
post 21 Aug, 2008 - 07:32 PM
Post #3


class Me : Perfection

Group Icon
Joined: 11 Jun, 2008
Posts: 1,105



Thanked 22 times

Dream Kudos: 1575
My Contributions


One thing i can say is that this would be a whole lot easier to read if you posted your code like flumer up there did. Use this

code.gif
User is offlineProfile CardPM

Go to the top of the page

flumer
post 22 Aug, 2008 - 01:44 AM
Post #4


New D.I.C Head

*
Joined: 8 Jun, 2007
Posts: 5


My Contributions


Really, I want to know the answer.
wink2.gif
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 04:29AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month