Skip to content

Instantly share code, notes, and snippets.

@emberfox
Created April 16, 2017 20:53
Show Gist options
  • Save emberfox/373d6f88c9b3a7ed56fa8c29785debea to your computer and use it in GitHub Desktop.
Save emberfox/373d6f88c9b3a7ed56fa8c29785debea to your computer and use it in GitHub Desktop.
Using getline problem
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
// Introduce a game
constexpr int WORD_LENGTH = 5;
cout << "Welcome to Bulls and Cows \n";
cout << "Can you guess the " << WORD_LENGTH;
cout << " letter isogram I'm thinking of?\n";
cout << endl;
string Guess = "";
// Get a guess from the player ----------------------------------------
cout << "Enter your guess: ";
cin >> Guess;
// Repeat the guess back to them
cout << "You chose " << Guess << endl;
cout << endl;
//Ask and repeat 1 ----------------------------------------------------
// Get a guess from the player
cout << "Enter your guess: ";
//string Guess = "";
cin >> Guess;
// Repeat the guess back to them
cout << "You chose " << Guess << endl;
cout << endl;
//Ask and repeat 2 ----------------------------------------------------
cout << "Enter your guess: ";
getline (cin, Guess);
cout << "You chose " << Guess << endl;
cout << endl;
//Ask and repeat 3 on getline ===========================================
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment