I am stuck in a play again loop

ever since instantiated the class, i am stuck in the do you want to play again loop
the code is as follows- for main
#include
#include
#include"FBullCowGame.h"
void PlayIntro();
void PlayGame();
bool AskToPlayAgain();
int main();
FBullCowGame BCGame;
int main()
{
bool bPlayAgain;
do {
PlayIntro();
PlayGame();
bPlayAgain=AskToPlayAgain();
} while (bPlayAgain);
return 0; // exit the game

}
void PlayIntro()
{
constexpr int Word_Length = 5;
std::cout << “welcome to bulls and cows\n”;
std::cout << “can you Guess the " << Word_Length << " letter isogram I’m thinking of? \n”;

}
void PlayGame()
{
BCGame.Reset();
int curtry=BCGame.GetCurrentTry();
int maxtry=BCGame.GetMaxTries();
std::string Guess;
//loop for number of reruns
for (int i = 1; i <= maxtry; i++)
{
std::cout<<"try " << curtry << ", enter your guess: ";
std::getline(std::cin, Guess);
std::cout << "your guess is: " << Guess << std::endl;
}

}
bool AskToPlayAgain()
{
std::string Response="";
std::cout << "do you want to play again?(Y/N) ";
std::getline(std::cin, Response);
return (Response[0] == ‘y’) ||(Response[0] == ‘Y’); //if response starts with y then yes
}

What’s in the BCGame.Reset() function?

void FBullCowGame::Reset()
{
int constexpr MAX_TRIES=8;
MyTries = 1;
MyMaxTries = MAX_TRIES;
return;
}
earlier i initiated another int called MyMaxTries in the function instead of using the one declared as a private method in the FBullCowGame.h
could this be the error?
by the way, the code works now :slight_smile:

Impossible to say w/o seeing the original code.

In future, to help debug these things, you can always insert std::cout “debug message here” before/after where you think the problem might exist. Change “debug message here” to be something meaningful of course. Additionally, you can start in debug mode to step through the code, though the instructor hasn’t gone over how to do that - so if you know how to do so, I’d recommend that method.

thanks a ton

Privacy & Terms