0
int f = 1; do { f++; int c, d; if ( yesNo == 'y' || yesNo == 'Y') { cout << "Player 1 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } else if ( yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 1" << endl; } cout << "Player 2 do you see this number on your card." << endl; cin >> yesNo; if (yesNo == 'y' || yesNo == 'Y') { cout << "Player 2 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } else if (yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 2" << endl; } cout << "Press 1 to continue generating random numbers." << endl; cin >> d; mf_numbers(d); } while (c < 5); 

I need help getting this do... while loop running. It skips past player one and works one time before I get an error box that says abort, retry close. I am currently using microsft visual studio.

here is the whole program itself. Linux users might have trouble getting the random number generator to work.

using namespace std; void mf_printcard1(int); void mf_printcard2(int); int mf_bingo(int); void mf_numbers(int); int main() { cout << " _________________________________________\n" " | B | I | N | G | O | |\n" " | ------|----|-----|-----|----|---- |\n" " | ------|----|-----|-----|----|---- |\n" " | ------|----|-----|-----|----|---- |\n" " | ------|----|-----|-----|----|---- |\n" " | ------|----|-----|-----|----|---- |\n" " _________________________________________\n" << endl; int a, b, c, d; char yesNo; cout << "\n\n\n\tCard choices" << endl; cout << "Bingo Card 1: 12, 5, 32, 18, 50, 46, 2, 29, 1, 30" << endl; cout << "Bingo Card 2: 43, 1, 6, 34, 8, 19, 23, 42, 41, 5" << endl; cout << "Bingo Card 3: 12, 5, 22, 45, 50, 13, 3, 8, 35, 18" << endl; cout << "Bingo Card 4: 34, 50, 1, 6, 21, 39, 8, 49, 9, 19" << endl; cout << "Bingo Card 5: 30, 14, 7, 28, 43, 34, 37, 48, 49, 18" << endl; cout << "Bingo Card 6: 12, 9, 10, 41, 50, 37, 11, 29, 2, 7, 47" << endl; cout << "Bingo Card 7: 15, 6, 35, 27, 8, 11, 32, 9, 39, 23" << endl; cout << "Bingo Card 8: 48, 21, 3, 9, 2, 32, 50, 31, 13, 38" << endl; cout << "Bingo Card 9: 20, 49, 28, 10, 8, 7, 14, 46, 19, 34" << endl; cout << "Bingo Card 10: 18, 26, 43, 5, 27, 45, 38, 50, 2, 29" << endl; cout << "Player 1 pick a card that you want." << endl; cout << "Be sure to write down your numbers." << endl; cin >> a; mf_printcard1(a); cout << "\n\n"; cout << "Now player 2, you pick a card that you want. It can not be the same as player 1" << endl; cout << "Be sure to write down your numbers." << endl; cin >> b; cout << "\n\n"; mf_printcard2(b); cout << "\nHere is your first number: 10" << endl; cout << "Player 1 is this number on your bingo card?" << endl; cout << "Press y for yes and n for no" << endl; cin >> yesNo; if (yesNo == 'y' || yesNo == 'Y') { cout << "Player 1 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } if (yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 1" << endl; } cout << "Player 2 is this number on your bingo card?" << endl; cout << "Press y for yes and n for no" << endl; cin >> yesNo; if (yesNo == 'y' || yesNo == 'Y') { cout << "Player 2 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } else if (yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 2" << endl; } cout << "Press 1 to continue generating random numbers." << endl; cin >> d; mf_numbers(d); int f = 1; do { f++; int c, d; if ( yesNo == 'y' || yesNo == 'Y') { cout << "Player 1 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } else if ( yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 1" << endl; } cout << "Player 2 do you see this number on your card." << endl; cin >> yesNo; if (yesNo == 'y' || yesNo == 'Y') { cout << "Player 2 how many numbers are on your card" << endl; cin >> c; mf_bingo(c); } else if (yesNo == 'n' || yesNo == 'N') { cout << "Sorry player 2" << endl; } cout << "Press 1 to continue generating random numbers." << endl; cin >> d; mf_numbers(d); } while (f < 5); cout << "Game over" << endl; return 0; } void mf_printcard1(int a) { cout << "\n"; cout << "Player 1 here is your card" << endl; cout << "\n"; if (a == 1) { cout << "Your Bingo numbers are: 12, 5, 32, 18, 50, 46, 2, 29, 1, 30" << endl; } else if (a == 2) { cout << "Your bingo numbers are: 43, 1, 6, 34, 8, 19, 23, 42, 41, 5" << endl; } else if (a == 3) { cout << "Your bingo numbers are: 12, 5, 22, 45, 50, 13, 3, 8, 35, 18" << endl; } else if (a == 4) { cout << "Your bingo numbers are: 34, 50, 1, 6, 21, 39, 8, 49, 9, 19" << endl; } else if (a == 5) { cout << "Your bingo numbers are: 30, 14, 7, 28, 43, 34, 37, 48, 49, 18" << endl; } else if (a == 6) { cout << "Your bingo numbers are: 12, 9, 10, 41, 50, 37, 11, 29, 2, 7, 47" << endl; } else if (a == 7) { cout << "Your bingo numbers are: 15, 6, 35, 27, 8, 11, 32, 9, 39, 23" << endl; } else if (a == 8) { cout << "Your bingo numbers are: 48, 21, 3, 9, 2, 32, 50, 31, 13, 38" << endl; } else if (a == 9) { cout << "Your bingo numbers are: 20, 49, 28, 10, 8, 7, 14, 46, 19, 34" << endl; } else if (a == 10) { cout << "Your bingo numbers are: 18, 26, 43, 5, 27, 45, 38, 50, 2, 29" << endl; } else { cout << "Not a valid option" << endl; } } void mf_printcard2(int b) { cout << "\n"; cout << "Player 2 here is your card" << endl; cout << "\n"; if (b == 1) { cout << "Your Bingo numbers are: 12, 5, 32, 18, 50, 46, 2, 29, 1, 30" << endl; } else if (b == 2) { cout << "Your bingo numbers are: 43, 1, 6, 34, 8, 19, 23, 42, 41, 5" << endl; } else if (b == 3) { cout << "Your bingo numbers are: 12, 5, 22, 45, 50, 13, 3, 8, 35, 18" << endl; } else if (b == 4) { cout << "Your bingo numbers are: 34, 50, 1, 6, 21, 39, 8, 49, 9, 19" << endl; } else if (b == 5) { cout << "Your bingo numbers are: 30, 14, 7, 28, 43, 34, 37, 48, 49, 18" << endl; } else if (b == 6) { cout << "Your bingo numbers are: 12, 9, 10, 41, 50, 37, 11, 29, 2, 7, 47" << endl; } else if (b == 7) { cout << "Your bingo numbers are: 15, 6, 35, 27, 8, 11, 32, 9, 39, 23" << endl; } else if (b == 8) { cout << "Your bingo numbers are: 48, 21, 3, 9, 2, 32, 50, 31, 13, 38" << endl; } else if (b == 9) { cout << "Your bingo numbers are: 20, 49, 28, 10, 8, 7, 14, 46, 19, 34" << endl; } else if (b == 10) { cout << "Your bingo numbers are: 18, 26, 43, 5, 27, 45, 38, 50, 2, 29" << endl; } else { cout << "Not a valid option" << endl; } } int mf_bingo(int c) { if (c == 0) cout << "You need to match get 5 more matching numbers to win." << endl; else if (c == 1) { cout << "You only need 4 more matching numbers to win" << endl; } else if (c == 2) { cout << "You only need 3 more numbers to win" << endl; } else if (c == 3) { cout << "You only need 2 more numbers to win" << endl; } else if (c == 4) { cout << "You only need 1 more number to win" << endl; } else if (c == 5) { cout << "You win!!!" << endl; } return true; } void mf_numbers(int d) { int xRan; srand(time(0)); xRan = rand() % 50 + 1; cout << xRan << endl; } 
3
  • Can you add more detail and missing relevant code? The above shouldn't compile but you say it does run so are you sure the code above is the same as on your machine? Commented May 11, 2015 at 1:43
  • I compiled your code on my machine and played the game, it asked me multiple times for both player one and two if a given number was on my card. Is this not happening for you? Commented May 11, 2015 at 2:01
  • 1
    This is not a minimal testcase. You have to debug it yourself and narrow down the problem to an isolated example program, then ask a question about that example program. Commented May 11, 2015 at 2:01

1 Answer 1

1

Its because your condition for the loop is (c < 5) when c is not defined until the loop body. You either need to change while (c < 5) to while (f < 5) or define c outside of the loop body.

Sign up to request clarification or add additional context in comments.

4 Comments

why does it skip when I ask player one if it is on their card
Ya good point, but c is defined in the loop's scope which should throw an error at compilation.
@joeyvarela To know for sure i would need to see some more of your code. You are starting f at 1 and incrementing it first thing in the body of your loop. With out seeing anymore of your code thats my best guess.
fixed that error of it skipping player 1. I missed a line. Now I cant get it to stop after a user enters that they have matched 5 numbers

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.