using namespace std;
const int NO_MATCH = 5;
const int TWO_MATCH = 1;
const int THREE_MATCH = 30;
int main ()
{
int choice;
int bank_amount = 0;
int game_amount = 0;
int transfer = 0;
int spins = 0;
char letter_a = 'a';
char letter_b = 'b';
char letter_c = 'c';
char letter_d = 'd';
int a_count;
int b_count;
int c_count;
int d_count;
int spin_count = 0;
int rand_letter;
int rand_letr_count;
srand(time(NULL));
cout<<"Welcome to Cletus's horrible Slots" <<endl; //Welcome user
cout<<" Chose one of the following: "<<endl; //User choice
cout<<"1.Check Balance"<<endl;
cout<<"2.Transfer Money"<<endl;
cout<<"3.Play the game"<<endl;
cout<<"4.Leave"<<endl;
cin>>choice;
bank_amount = 100* ( rand() % 10 + 2);
switch(choice)
{
case 1:
cout<<"Bank balance "<<bank_amount<<endl; //Bank Balance
cout<<"Game balance "<<game_amount<<endl; // Game Balance
case 2:
cout<<"How much money would you like to transfer (multiples of 100?)"
<<endl; //Transfer money to slot machine
cin>>transfer;
break;
transfer *= 100;
if (bank_amount >= transfer)
{
if(bank_amount > 5)
{
bank_amount = bank_amount + transfer;
game_amount = game_amount - transfer;
}
cout<<"Wow! You Suck game over!"<<endl;
cout<<"Please give me the amount you actually have."<<endl;
cin>> transfer;
}
case 3:
cout<<"How many times would you like to spin?"<<endl; //Number of spins
cin>>spins;
if(game_amount > (5 * spins))
{
cout<<"You are going to empty out your account."
"Pick a smaller amount of spins"<<endl;
cin>>spins;
break;
}
for(spin_count = spins; spin_count > 0; spin_count--)
{
a_count = 0;
b_count = 0;
c_count = 0;
d_count = 0;
}
else
{
cout<<" Bank Amount: "<<bank_amount<<endl;
cout<<" Game Amount: "<<game_amount<<endl;
cout<<"LOSE $5!!" <<endl;
game_amount = game_amount - NO_MATCH;
}
}
case 4:
{
cout<<" Bank balance: "<<bank_amount<<endl;
cout<<" Game balance: "<<game_amount<<endl;
bank_amount += game_amount;
cout<<" Ending bank balance is: " <<bank_amount<<endl;
cout<<" Ending game balance is: "<<game_amount<<endl;
cout<<" Thank you for playing, have a great day."<<endl;
return 0;
}
You either do a sanity check for anything less than zero, or you switch to using unsigned integers. Where in your code are you trying to prevent the negative numbers from showing up?
I don't get why though. From what I understand of your code a negative value for 'game_amount' is perfectly valid. It indicates that the player has incurred a net loss playing the game.
I tried many ways of doing this but there is a certain way I have to submit which is not what I'm getting.
seed the random number generator to ..... ummm. ..... 5, yeah 5.
choose option 3
choose option 1
choose option 2 and attempt to transfer $1200
choose option 2 and attempt to transfer -$300
choose option 2 transfer $200 to game balance
choose option 3 and request 300 spins
choose option 3 and request -5 spins
choose option 3, spin 40 times
choose option 3, spin 1 time
quit