#include <iostream>
#include <string>
usingnamespace 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?