looping question

How would i keep track of money spent? and items bought when i loop and how do i say i want multiple items meaning if i want to purchase more than one teeshirt or mug.




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
 #include<iostream>
 using namespace std;
 int main()
 {
    char symb;
    int item_purch, numb_item_purch, quit, answ;
    double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;

    cout << "You have 30 dollars to spend.\n";
    do
    {
        cout << endl;
    cout << "What do you want to buy today?\n";
     tot_mon = 30;

            cout << " A) Mugs $2.50 " << endl;
            cout << " B) teeshirt $9.50 " << endl;
            cout << " C) Pens .75 cents " << endl;
            cout << " D) Quit" << endl;
            cout << " Enter your letter and press Return when finished" << endl;
            cin >> symb;

            cout.setf(ios::fixed);
            cout.setf(ios::showpoint);
            cout.precision(2);


        switch (symb)
        {
            case 'A':;
            case 'a':;
            cout << " You have choosen A) mugs for $2.50 \n" << endl;
            mug = 2.50;
            curr_cash = tot_mon - mug;
            cout << " You have " << curr_cash << " remaining \n " << endl;
            tot_mon = 30;

            break;
            case 'B':;
            case 'b':;
            cout << " You have choosen B) teeshirt for $9.50 " << endl;
            teeshirt = 9.50;
            curr_cash = tot_mon - teeshirt;
            cout << " You have " << curr_cash << " remaining \n " << endl;
            tot_mon = 30;
            break;

            case 'C':;
            case 'c':;
            cout << " You have choosen C) Pens for .75 cents " << endl;
            pen = .75;
            curr_cash = tot_mon - pen;
            cout << " You have " << curr_cash << " remaining \n " << endl;
            tot_mon = 30;
            break;

            case 'D':;
            case 'd':;
            cout << " You have choosen D) which means you want to Quit" << endl;
            quit = 0;
            break;

            default:
            cout << "Input error. Select again" << endl;
        }
        if ( curr_cash = 0)
        {
            cout << "You need more cash, you dont have enough\n" << endl;
            curr_cash = tot_mon - mon_spent;
        }
        else
        {
            cout << " Would you like anothe purchase, please choose another letter.\n" << endl;

                            }
        } while ( curr_cash <= 0);
      
        cout << "Thank you for shopping.\n";

    return 0;
 }
[/code]
case 'D':;

Does that compile and execute correctly with the superfluous ';'? You are already keeping track of cash that is left. It is easy enough to determine amount spent with a simple calculation. I recommend creating a common getInput function which would make your life easier. If you want to ask for number of items then you have to have an extra cin operation to ask the user for quanity of the item.
Topic archived. No new replies allowed.