Hi, I've recently coded a small text based game. Everything works great except for my game won't play again. I've tried multiple methods but none seem to work any how here's the code.
#include <iostream>
#include <cstdlib>
#include <time.h>
usingnamespace std;
int main()
{
int gameselect;
bool playagain = true;
char playagainchar;
cout<<"Welcome to: \n\n";
cout<<"*****************\n";
cout<<"**Ryan's Casino**\n";
cout<<"*****************\n";
cout<<"Great Family Fun!\n\n";
cout<<"Please select a game\n";
cout<<"1. Guess a Number\n";
cout<<"More games coming soon!\n";
cout<<"What game would you like to play (Game Number): ";
cin>> gameselect;
cin.ignore();
cout<<"\n\n\n";
if (gameselect == 1){
int select;
cout<<"Welcome to Guess a Number\n";
cout<<"1. Rules\n";
cout<<"2. Play\n\n";
cout<<"Please select: ";
cin>> select;
cin.ignore();
cout<<"\n\n";
switch ( select ) {
case 1:
cout<<"In Guess a Number, your goal is to guess a randomly generated number \nbetween 1 and 1000.";
cout<<"Every time you guess the computer will tell \nyou if you are above or below.\n";
cout<<"Press enter to play!";
cin.get();
cout<<"\n\n";
case 2:
while (playagain == true){
int guess, number, nog;
nog = 1;
srand ( time(NULL) );
number = rand() % 1000 + 1;
cout << "Guess a number: " ;
cin>> guess;
if (guess == number){
cout<<"You guessed it! \nit took you"<<nog<<"guesses";
}
if (guess<number) {
cout<<"You're guess was to low! \n";
}
if (guess>number) {
cout<<"You're guess was to high! \n";
}
while (guess != number) {
cout<<"Guess again: ";
cin>>guess;
if (guess<number) {
cout<<"You're guess was to low! \n" ;
}
if (guess>number) {
cout<<"You're guess was to high! \n";
}
nog++;
}
cout<<"You guessed it! In "<<nog<<" guesses!\n\n";
cout<<"Would you like to play again Y/N: ";
cin>>playagainchar;
cout<<"\n\n";
if(playagainchar != 'y') playagain = false;
break;
}
}
cin.get();
}
}