program wont solve

I can ask the user how much he will pay but the program wont solve it.
change=cash-total(items bought)



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <iomanip>
#include <string>
#include <conio.h>

using namespace std;

void display_menu();
void tax(float);

float total = 0, cash=0;

int main() {
    char choice;
    bool more = true;
    cout << setiosflags(ios::showpoint) << setiosflags(ios::fixed) << setprecision(2);

    while(more) { //loop until the user wants more
        cout << "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n";
        cout << "Welcome to Jimmy's Snack Bar!" << endl;
        display_menu();
        cout << "Please enter the letter of your selection: ";
        cin >> choice;
        switch (choice) {
        case 'S':
        case 's':
            cout << "Sandwich - P30.00" << endl;
            total+=30;
            break;
        case 'C':
        case 'c':
            cout << "Chips - P50.00" << endl;
            total+=50;
            break;
        case 'P':
        case 'p':
            cout << "Pansit - P20.00" << endl;
            total+=20;
            break;
        case 'H':
        case 'h':
            cout << "Hotdog - P25.00" << endl;
            total+=25;
            break;
        case 'D':
        case 'd':
            cout << "Coke - P15.00" << endl;
            total+=15;
            display_menu();
            break;
        case 'B':
        case 'b':
            cout << "Burger - P25.00" << endl;
            total+=25;
            break;
        case 'X' :
        case 'x':
            cout << "Canceled, please start over." << endl;
            total = 0;
            break;
        case 'T' :
        case 't':
            tax(total);
            cout<<"how much do you want to pay."<<endl;
            cin>>cash;
            more = false; //stop the loop
            
            //_____________

            
            
            break;
        default:
            cout << "Ooops! something went wrong.. :(\n\n";
            return 0; //end the program
        }
        cout << "Your current total is: P "<< total << "\n\n";
        
    
    }
    return 0;
}




void display_menu() {
    cout << endl;
    cout << "S - Sandwich P30.00" << endl;
    cout << "C - Chips P50.00" << endl;
    cout << "P - Pansit P20.00" << endl;
    cout << "H - Hotdog P25.00" << endl;
    cout << "D - Coke P15.00" << endl;
    cout << "B - Burger P25.00" << endl;
    cout << "X - Cancel sale and start over" << endl;
    cout << "T - Total the sale" << endl;
    cout << "All items have additional 12% tax." << endl;
}


void tax(float total) {
    cout << endl;
    cout << "Sub-total: " << total << endl;
    cout << "+ Tax : " << total*0.12 << endl;
    cout << "Total : " << total + (total*0.12) << endl;   
    cout << "Total : " << cash-(total + (total*0.12)) << endl;//problem is this one
    
   
    


    
}
Last edited on
You're only calling the menu again if the user enters D or d. If you want them to be able to pick something again after every selection, I would copy that into each of the switch cases.
Does it compile? I guess one error is that cin>> cash; is after the call of tax(...), but u need to have it before.
yes it does compile. my problem here is that i want the program to compute for the change of the customer
So if u buy a burger and then enter 50 as cash the output is?
Well, add the call to display the menu again in each switch statement, then call the calcTax function after you asked how much cash they have.
@tunaPete that should be 50-(25+(25xtax)
oghmaosiris - no that wont do it. already tried it
What is the actual ouptut? Do u get a numeric value? I repeat (and ogh said this too):

1
2
3
tax(total);
cout<<"how much do you want to pay."<<endl;
cin>>cash;


Should be:

1
2
3
cout<<"how much do you want to pay."<<endl;
cin>>cash;
tax(total);
Last edited on
If you don't put it after the cash, then you're always going to be sending 0 to the function call.
@tunaPete no that still wont do. and yes the program should give you a numerical value.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: d
Coke - P15.00

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Your current total is: P 15.00

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: t

Sub-total: 15.00
+ Tax : 1.80
Total : 16.80
Total : -16.80
how much do you want to pay.
 50
Your current total is: P 15.00

Press any key to continue . . .


this is the output that I got with your code verbatum.

It seems that without adding the call to the menu after each selection, you're going to go to the default in the next iteration of the loop. You need to code something to let the user enter another selection after the first one in each switch statement.Ignore this, lol... I was wrong!

Also, CALL THE TAX AFTER THE CASH IS INPUT.
Last edited on
@oghmaosiris can you give me the codes that i should place. i dont think i understand you clearly.
No, that's what you need to figure out on your own.

If I tell you, then you won't fully understand and in the future, you'll be stuck again on a similar problem.
if you ordered a coke. it will cost 16.80

you paid 50

so 50-16.80=33.20

the number in bold should be the one that will appear

@oghmaosiris just to let you know you could press CCC and it would order 3 cokes. i just need how to figure out how to compute for the change.
ok. Then switch the call to tax and the input for cash. I did and lo and behold, it worked. The change was calculated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: c
Chips - P50.00
Your current total is: P 50.00

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: c
Chips - P50.00
Your current total is: P 100.00

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: c
Chips - P50.00
Your current total is: P 150.00

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Welcome to Jimmy's Snack Bar!

S - Sandwich P30.00
C - Chips P50.00
P - Pansit P20.00
H - Hotdog P25.00
D - Coke P15.00
B - Burger P25.00
X - Cancel sale and start over
T - Total the sale
All items have additional 12% tax.
Please enter the letter of your selection: t
how much do you want to pay.
1000

Sub-total: 150.00
+ Tax : 18.00
Total : 168.00
Total : 832.00
Your current total is: P 150.00

Press any key to continue . . .
call to tax - are you referring to:

1
2
3
4
5
void tax(float total) {
    cout << endl;
    cout << "Sub-total: " << total << endl;
    cout << "+ Tax : " << total*0.12 << endl;
    cout << "Total : " << total + (total*0.12) << endl; 


and when you said:
input for cash you are referring to

1
2
cout<<"how much do you want to pay."<<endl;
            cin>>cash;


am i right?
great you where right!!! ahahahah thanks great help!!
I would recommend using cout.fill() instead of cout << "-=-=-=-";
Topic archived. No new replies allowed.