Can anyone help me out on this thing. This is my first assignment and can't figure it out. But I can't get out of the loop after I roll the point value or roll a 7 to lose after the first roll. The game will just keep going. Also I need to a way to error trap at the end when the game asks if you want to continue. I have to loop that to where if the user enters something other than Y or N then it will repeat. But if its a N then you get the good bye message and exit. If the user enters Y, then the game starts over. Thanks for the help!
Code:#include <iostream> #include <cstdlib> #include <ctime> using namespace std; void main() { srand((unsigned)time(NULL)); int firstRoll, nextRoll, die1, die2; char playAgain; cout << "Welcome to Craps!" << endl << endl; do { cout << "The game is about to begin..." << endl; system("pause"); cout << endl; die1 = (rand() % 6 + 1); die2 = (rand() % 6 + 1); firstRoll = die1 + die2; cout << "You rolled a " << die1 << " and a " << die2 << " for a total of " << firstRoll << "." << endl; if (firstRoll == 7 || firstRoll == 11) { cout << "Congratulations, you win!" << endl; } else if ((firstRoll == 2) || (firstRoll == 3) || (firstRoll == 12)) { cout << "Sorry, you lose" << endl; } else { do { cout << "Your point value is: " << firstRoll << endl; system("pause"); cout << endl; die1 = (rand() % 6 + 1); die2 = (rand() % 6 + 1); nextRoll = die1 + die2; cout << "You rolled a " << die1 << " and a " << die2 << " for a total of " << nextRoll << "." << endl; if (nextRoll == firstRoll) { cout << "Congratulations, you rolled your point value. YOU WIN!" << endl << endl; } else if (nextRoll == 7) { cout << "Sorry, you lost." << endl; } else { cout << "Please roll again." << endl; system("pause"); cout << endl; } } while ((nextRoll != 7) || (nextRoll != firstRoll)); } cout << "Would you like to play again (Y or N)? " << endl; cin >> playAgain; if ((playAgain == 'n') || (playAgain == 'N')) { cout << "Thanks for playing!" << endl; system("pause"); } else if ((playAgain == 'y') || (playAgain == 'Y')) { } else { cout << "Please enter either Y or N!" << endl; } //}while; }while ((playAgain == 'y') || (playAgain == 'Y')); }// end of main



LinkBack URL
About LinkBacks



