Original Post
Hello, I'm workin' on a slot machine program and for some reason I'm having some issues with the menu. Selecting one breaks out of the menu loop and will allow you to play the slot machine game. Selecting two quits the game. And anything else it prints onto the console "Please enter a valid option." For some reason, when an invalid number is entered it prints but it doesn't loop back. So yeah, slightly confused. *I apologize, but the code snippet tool was not cooperating with me, only showing a portion of whatever code I put in*
Here's the code:
#include
#include
#include
using namespace std;
int Random( int, int );
int main()
{
//---- Initialization-------------------------------------------------
int low;
int high;
int chips = 1000;
int hold = 0;
bool quit = false;
//----End Init--------------------------------------------------------
// Start Game---------------------------------------------------------
while( !quit ){
//----Menu--------------------------------------------------------
while( hold <= 0 )
{
cout << "Player's chips: $" << chips << endl;
cout << "1) Play slot. 2) Exit." << endl;
cin >> hold;
if ( hold == 1 )
break;
if ( hold == 2 )
quit = true;
else
cout << "Please select a valid option" << endl;
}
//----End Menu----------------------------------------------------
}
cin.get();
cin.get();
return 0;
//---End Game---------------------------------------------------------
}
int Random( int low, int high )
{
srand(time(0));
int a = (rand() + low) % high;
return a;
}
Here's the code:
#include
#include
#include
using namespace std;
int Random( int, int );
int main()
{
//---- Initialization-------------------------------------------------
int low;
int high;
int chips = 1000;
int hold = 0;
bool quit = false;
//----End Init--------------------------------------------------------
// Start Game---------------------------------------------------------
while( !quit ){
//----Menu--------------------------------------------------------
while( hold <= 0 )
{
cout << "Player's chips: $" << chips << endl;
cout << "1) Play slot. 2) Exit." << endl;
cin >> hold;
if ( hold == 1 )
break;
if ( hold == 2 )
quit = true;
else
cout << "Please select a valid option" << endl;
}
//----End Menu----------------------------------------------------
}
cin.get();
cin.get();
return 0;
//---End Game---------------------------------------------------------
}
int Random( int low, int high )
{
srand(time(0));
int a = (rand() + low) % high;
return a;
}