-
somehow the game stopped running after I added the AskToPLayNewGame function. I can’t figure out why. The program doesn’t even let me type in the first 5 guesses. It crashes immediately after telling me to make the first guess.
-
Also the using namespace std; function did not work for me. I was getting errors sometimes.
-
If I try to use endl; then the editor tells me i have overloaded the function. What does this mean?
//
// main.cpp
// cows and bulls game
//
// Created by Skjalg Remme on 09/04/2017.
// Copyright © 2017 Skjalg Remme. All rights reserved.
//
#include
#include
void PrintIntro ();
std:: string GetGuess ();
std:: string printResult();
void PlayGame();
bool AskToPLayNewGame ();
//This is where the code initializes
int main ()
{
PrintIntro();
PlayGame();
std:: cout << AskToPLayNewGame();
return 0;
}
//functions in this game are placed below here and called before the main function is called.
//Introduces the game and sets word length
void PrintIntro ()
{
constexpr int word_length = 5;
std::cout << “Welcome to the Cows and Bulls game where you guess a " << word_length <<” letter isogram\n";
std::cout << "Please make your guess by typing in the word:\n";
return;
}
//gets the player guess
std:: string GetGuess ()
{
std:: string Guess = “”;
std:: getline ((std:: cin), Guess);
std:: cout << endl;
return Guess;
}
//Plays the game and sets number of turns
void PlayGame()
{
constexpr int Number_of_guesses = 5;
for (int count=1; count<=Number_of_guesses; count++)
{
std:: string Guess = GetGuess();
std:: cout << “You have guessed” << Guess << endl;
}
return;
}
bool AskToPLayNewGame ()
{
std:: cout << “Do you want to play again?\n”;
std:: string Response = “”;
std:: getline (std:: cin, Response);
return (Response[0] == ‘y’) || (Response[0] == ‘Y’);
}