Play Again

Hey, I'm a beginner at coding and I have to write a code for two guessing games, one where the user guesses and the other where the computer guesses the number. After winning, they have the option to play again, however, mine won't do that. Can anyone see why?

#include <cstdlib>
#include <iostream>
#include <ctime>//required for the time function
using namespace std;


void playGame1()
{
while (true) {
srand(int(time(NULL)));//srand and time function
char answer;
int tries = 0;

do
{
int number_guess = rand() % 100 + 1;//rand function
cout << "choose a number between 1 and 100 and I'll guess it." << endl;
cout << "is " << number_guess << " your number?(y/n)" << endl;
++tries; // calculates how many tries it took the computer
cin >> answer;
if (answer == 'y')
cout << "It took me " << tries << " tries! " << endl;
} while
(answer == 'n'); // continue until the computer is wrong.
while (true){
while (true) {
std::cout << "Would you like to play again (Y/N)? ";
std::cin >> answer;
std::cin.ignore();

if (answer == 'n' || answer == 'N' || answer == 'y' || answer == 'Y') {
break;
}
else {
std::cout << "Please enter \'Y\' or \'N\'...\n";
}
}

if (answer == 'n' || answer == 'N') {
std::cout << "Thank you for playing!";
break;
}
else {
std::cout << "\n\n\n";
}
}

std::cout << "\n\nEnter anything to exit. . . ";
std::cin.ignore();
break;
}
}
void playgame2()
{
while (true)
{
int number;
int randomNum;
bool tryAgain = true;
char reply;
int guess;


cout << "Guess a Number between 1 and 100" << endl;

while (tryAgain)
{

srand(time(0));
randomNum = rand() % 100 + 1;


cout << "\nTry and guess my number: " << endl;
cin >> number;
int played = 0;
while (number != randomNum)
{
played++;
if (number < randomNum)
{
cout << "Your guess is too low...try again: " << endl;
cin >> number;
}
if (number > randomNum)
{
cout << "Your guess is too high...try again: " << endl;
cin >> number;
}

}

if (number == randomNum)
{
cout << "Congratulations you have won." << endl;
cout << "You took " << played << " tries." << endl;
break; // finish and ask for y or n
}
}
cout << "Play Again? Enter y or n: " << endl;
cin >> reply;
if (reply != 'y')
{
tryAgain = false;
cout << "Bye!" << endl;
}
}

int main()
{
int gameNumber = 0
//pick whether to:
playGame1();
//or
playGame2();
}
Also, it's not letting the user pick which game they want to play, it just goes straight to playing the first game
int main()
{
int gameNumber = 0
cin >> gameNumber;
if(gameNumber==1)
playGame1();
if(gameNumber==2)
playGame2();

}
Topic archived. No new replies allowed.