menu selection, money problem

What is wrong with my code, sometimes my moeny goes into a negative and sometimes not?
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
#include <iostream>
#include <string>

using namespace std;

int main()
{

    int money =1000, choiceAmount, tv = 0, dvd = 0, blu = 0;
    char choice;

        startmenu:

    cout << "You have " << money << " dollars. What would you like to purchase? " <<endl <<endl;
    cout << "1) TV Set " <<endl;
    cout << "2) DVD Player " <<endl;
    cout << "3) Blu Ray Player " <<endl;
    cout << "4) exit menu" <<endl;

    cin >> choice;


        if(choice == '1')//choice for TV Sets
        {
            cout << endl <<endl;
            cout << "How many TV Sets would you like to purchase?" <<endl;
            cout << "TV Sets run at $500/ea"<<endl;

            cin >> choiceAmount;
            if(money < 500)//not enough money
            {
                cout << "You do not have enough money!"<<endl;
                goto startmenu;
            }
            else
            {
                money = money - (choiceAmount * 500);
                tv = choiceAmount;
                goto startmenu;
            }

        }//end of if choice

        if(choice == '2')//choice for dvd player
        {
            cout << endl <<endl;
            cout << "How many DVD Players would you like to purchase?" <<endl;
            cout << "DVD Players run at $100/ea"<<endl;

            cin >> choiceAmount;
            if(money < 100)//not enough money
            {
                cout << "You do not have enough money!"<<endl;
                goto startmenu;
            }
            else
            {
                money = money - (choiceAmount * 100);
                dvd = choiceAmount;
                goto startmenu;
            }

        }//end of if choice

                if(choice == '3')//choice for blu ray
        {
            cout << endl <<endl;
            cout << "How many Blu Ray Players would you like to purchase?" <<endl;
            cout << "TV Sets run at $300/ea"<<endl;

            cin >> choiceAmount;
            if(money < 300)//not enough money
            {
                cout << "You do not have enough money!"<<endl;
                goto startmenu;
            }
            else
            {
                money = money - (choiceAmount * 300);
                blu = choiceAmount;
                goto startmenu;
            }

        }//end of if choice



    if(choice == '4')
    {

    cout << "You have $" << money << " left." <<endl;
    cout << "TV Sets: " << tv << " at $500/each" <<endl;
    cout << "DVD Players: " << dvd << " at $100/each"<<endl;
    cout << "Blu Ray Players: " << blu << " at $300/each" <<endl;
    }//end of choice exit

}//end of main 
ok i figured out why it is negative, the if is only false if you have less than that amount, but if you have 1000 and you choose 3 tv's than it will bring you to -500 allowing you to go to a negative

How would you stop that and get the intended results?
closed account (DSLq5Di1)
1
2
            cin >> choiceAmount;
            if(money < 500 * choiceAmount)//not enough money 
?
Topic archived. No new replies allowed.