Skip to content

Instantly share code, notes, and snippets.

Created July 18, 2017 22:37
Show Gist options
  • Save anonymous/3515097bb49a3a7858543426c61f0dc8 to your computer and use it in GitHub Desktop.
Save anonymous/3515097bb49a3a7858543426c61f0dc8 to your computer and use it in GitHub Desktop.
Simplifying with functions video
#include <iostream>
#include <string>
void PrintIntro();
std::string Guessing();
int main() {
PrintIntro();
Guessing();
return 0;
}
void PrintIntro() {
// introduce the game
constexpr int WORD_LENGHT = 5;
std::cout << "Welcome to Bulls & Cows, a fun word game!\n";
std::cout << "Can you guess the " << WORD_LENGHT << " letter word I'm thinking now?\n";
std::cout << std::endl;
return;
}
std::string Guessing() {
// get a guess from the player
std::cout << "Enter your guess:\n";
std::string Guess = "";
std::getline(std::cin, Guess);
std::cout << std::endl;
// get another guess
std::cout << "Your guess was: " << Guess << std::endl << std::endl;
std::cout << "Please take another guess!\n";
std::getline(std::cin, Guess);
return Guess;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment