Yet another poker game

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.

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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
		// 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
										else if( 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
					else if( 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 
Topic archived. No new replies allowed.