Skip to content

Instantly share code, notes, and snippets.

@Azada123
Created July 1, 2018 10:53
Show Gist options
  • Save Azada123/fdea90035bb35e9ec84ca74221e957c2 to your computer and use it in GitHub Desktop.
Save Azada123/fdea90035bb35e9ec84ca74221e957c2 to your computer and use it in GitHub Desktop.
// BullCowGame.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
void PrintIntro();
void PlayGame();
std::string GetGuess();
bool isPlayingAgain();
constexpr int NUMBER_OF_TURNS = 5;
constexpr int WORD_LENGTH = 5;
int main()
{
PrintIntro();
std::cout << std::endl;
do
{
PlayGame();
}
while (isPlayingAgain());
return 0;
}
// Introduce the game
void PrintIntro()
{
std::cout << "Welcome to Bulls and Cows, A fun wordgame." << std::endl;
std::cout << "Can you guess the " << WORD_LENGTH << " letter isogram I´m thinking of?" << std::endl;
return;
}
void PlayGame()
{
for (int count = 0; count < NUMBER_OF_TURNS; ++count)
{
std::string Guess = GetGuess();
std::cout << "Your guess is " << Guess << std::endl;
std::cout << std::endl;
}
}
// Get a guess from player and print it back
std::string GetGuess()
{
std::string Guess = "";
std::cout << "Enter your guess ? ";
std::getline(std::cin, Guess);
return Guess;
}
bool isPlayingAgain()
{
std::string Response = "";
std::cout << "Do you want to play again" << std::endl;
getline(std::cin, Response);
std::cout << std::endl;
return (Response[0] == 'y' || Response[0] == 'Y');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment