This is my implementation of the for loop in lesson 26 of UE4 C++ Course.
Comments are welcome
#include <iostream>
#include <string>
using namespace std;
constexpr int WORD_LENGTH = 9;
constexpr int MAX_GUESSES = 5;
// application function prototypes
void PrintIntro();
string GetGuess();
// application entry point
int main() {
PrintIntro();
string Guess = "";
for (int i = 0; i < MAX_GUESSES; i++) {
Guess = GetGuess();
// print guess back to the player
cout << "You entered: " << Guess << "\n";
}
cout << endl;
return 0;
}
// introduce the game
void PrintIntro() {
cout << "Welcome to Bulls and Cows!\n";
std::cout << "Guess the " << WORD_LENGTH << " letter isogram :D\n";
}
// get a guess from the player
string GetGuess() {
cout << "Enter your guess: ";
string Guess = "";
getline(cin, Guess);
cout << endl;
return Guess;
}