Unexplained Point in Loop Clarity

So in removing the guess output from “GetGuess” and moving it to the loop one point was not explained.

This was the loop statement beforevoid Playgame(){
//Loop for the number of turns asking for guesses
constexpr int limit=5;
for (int count=1; count <= limit; count++){
GetGuessandPrint();
}

We end up with the loop like this:
for (int count=1; count <= limit; count++){
string Guess = GetGuess();
cout << "You entered: " << Guess << endl;
}

It wasn’t clear that in defining string Guess = GetGuess() we no longer call the function separately which is why I initially did this in the loop:

for (int count=1; count <= limit; count++){
     string Guess = GetGuess();
     Getguess();
      cout << "You entered: " << Guess << endl;
}

This caused a very strange error and an infinite loop (not sure why since you would think the loop would still just run 5 times). After seeing the solution it makes sense now but I am not sure it was clear.

Privacy & Terms