I have been through this over and over and compared with the example on GitHub but I’m having a problem. When I compile and run it waits for my input (no prompt) and then after I’ve typed something it asks me to enter my guess and prints the guess all on one line:
Here is my code - any idea what I’ve done wrong or is it just an Xcode quirk?
#include <iostream>
#include <string>
using namespace std;
void PrintIntro();
void PlayGame();
string GetGuess();
bool AskToPlayAgain();
// The entry point of our application
int main()
{
PrintIntro();
PlayGame();
AskToPlayAgain();
return 0; // exit the application
}
// introduce the game
void PrintIntro()
{
constexpr int WORD_LENGTH = 9;
cout << "Welcome to Bulls and Cows, a fun word game.\n";
cout << "Can you guess the " << WORD_LENGTH;
cout << " letter isogram I'm thinking of?\n";
cout << endl;
return;
}
void PlayGame()
{
// loop for the number of turns asking for guesses
constexpr int NUMBER_OF_TURNS = 5;
for (int count = 1; count <= NUMBER_OF_TURNS; count++)
{
string Guess = GetGuess();
cout << "Your guess was: " << Guess << endl;
cout << endl;
}
}
string GetGuess()
{
// get a guess from the player
cout << "Enter your guess: ";
string Guess = "";
getline (cin, Guess);
return Guess;
}
bool AskToPlayAgain ()
{
cout << "Do you want to play again? ";
string Response = "";
getline (cin, Response);
cout << "Is it y? " << (Response[0] == 'y');
cout << endl;
return false;
}