This code loops when alpha letters are inputted into an int variable.
The problem I am having is in cin >> bet;(line 52), bet is an int variable and I dont know how to make the user only input int characters. Also when you input non integers it goes back to the beginning of the loop as normal, but when you select the bet option it doesnt take input anymore, as if it skips the cin >> bet; line.
I believe that all I would have to do is clear the buffer for 'int bet', but I have no clue how to do this...
Thanks in advanced and many thanks for anyone with a helpful response.
// players changed cards as needed and now need to decide what to bet or they can fold if they find
// that they will not have a winning hand
// for taking each players bets
for( int p = 0; p < m_players.GetNumPlayers(); p++ ) {
if( m_players[ p ] ) { // check if player is present
// displaying next players turn
cout << "Next screen is for ";
clr.setcolor( 10 );
cout << "Player " << p + 1 << endl;
cout << m_players[ p ]->GetName() << " ";
clr.setcolor( 15 );
takingBet = true;
system( "pause" );
system( "cls" );
while( takingBet ) {
clr.Title( TotalBets() ); // displays the title of the game
cout << "Name: " << m_players[ p ]->GetName() << endl
<< "$ " << m_players[ p ]->GetStack() << endl
<< "Cards in Hand;" << endl;
for( int c = 0; c < 5; c++ ) {
cout << c + 1 << ". ";
clr.setcolor( 14 );
cout << *m_players[ p ]->GetHand()[ c ] << endl;
clr.setcolor( 15 );
} // end for to show hand
clr.Line(); // draw line
clr.BetMenu(); // draw bet menu
cout << "The previous player bet $";
clr.setcolor( 13 );
cout << preBet << endl;
clr.setcolor( 15 );
cout << "You can place a BET, or FOLD." << endl;
option = ' '; // resets option to blank
option = _getch();
// how much will the player bet
if( option == 'B' || option == 'b' ) {
finishBet = true;
while( finishBet ) {
cout << "How much would you like to bet? " << endl;
bet = 0;
cin >> bet;
if( bet != 0 ) {
if( bet <= m_players[ p ]->GetStack() ) {
if( bet >= preBet ) {
cout << "Your betting $";
clr.setcolor( 13 );
cout << bet;
clr.setcolor( 15 );
cout << " ? Y/N" << endl;
option = ' '; // resets option to blank
option = _getch();
if( option == 'Y' || option == 'y' ) {\
system( "cls" );
m_players[ p ]->Bet( bet );
preBet = bet;
clr.Title( TotalBets() ); // displays the title of the game
cout << "Name: " << m_players[ p ]->GetName() << endl
<< "$ " << m_players[ p ]->GetStack() << endl
<< "Cards in Hand;" << endl;
for( int c = 0; c < 5; c++ ) {
cout << c + 1 << ". ";
clr.setcolor( 14 );
cout << *m_players[ p ]->GetHand()[ c ] << endl;
clr.setcolor( 15 );
} // end for displaying current hand
clr.Line(); // draw line
cout << "You bet $";
clr.setcolor( 13 );
cout << bet << " " << endl;
clr.setcolor( 15 );
system( "pause" );
system( "cls" );
finishBet = false;
takingBet = false;
} // end if Yes option
elseif( option == 'N' || option == 'n' ) {
finishBet = false;
system( "pause" );
system ( "cls" );
} // end else if No option
} // end if bet > preBet
else {
cout << "You have to match or bet more than " << m_players[ p - 1 ]->GetName() << endl;
finishBet = false;
system( "pause" );
system( "cls" );
} // end else bet > preBet
} // end if player has enough money
else {
cout << "Your bet is too high. You can only bet with the amount of money you have." << endl;
finishBet = false;
system( "pause" );
system( "cls" );
} // end else player doesnt have enough money
} // end if bet != 0
else {
cout << "Please try again. Your bet has to be greater than 0." << endl;
finishBet = false;
system( "pause" );
system ( "cls" );
} // end else if bet is 0
} // end while finishBet
} // end if option <Place Bet>
// player folds and loses the match
elseif( option == 'F' || option == 'f' ) {
// check every card that the player has
for( int hC = 0; hC < 5; hC++ ) {
Card *c = m_players[ p ]->GetHand()[ hC ];
m_players[ p ]->GetHand()[ hC ] = NULL;
// Return card back to deck
m_deck.ReturnCard(c);
} // end for check players cards
system( "cls" );
cout << "Previous player has folded" << endl;
finishBet = false;
takingBet = false;
} // end if option FOLD
else {
system( "cls" );
} // end else
} // end while player that has not folded and places a bet
} // end check for players
} // end for taking each players bets