Iterating with For & While Loops

I’m including the my solution for Section 2 Lecture 18. I didn’t hear anything about his Magic numbers challenge in the video though. I’ve gone back and listened a couple times.

#include <iostream>
#include <string>

using namespace std;

void PrintIntro();
string GetGuessAndPrintBack();

int main()
{
	PrintIntro();
	for (int count = 1; count <= 5; count++)
	{
		GetGuessAndPrintBack();
		cout << endl;
	}
	return 0;
};
//Introduce the game.
void PrintIntro() {
	constexpr int WORD_LENGTH = 3;
	cout << "Welcome to bulls and cows, A fun word game.\n";
	cout << "Can you guess the " << WORD_LENGTH;
	cout << " letter isogram I'm thinking of?\n";
	cout << endl;
	return;
}
// Get a guess from the player.
string GetGuessAndPrintBack() {
	cout << "Enter your guess: ";
	string Guess = "";
	getline(cin, Guess);
	// Prints guess back to the player.
	cout << "Your guess was: " << Guess << endl;
	return Guess;
}

Hello everyone, this is my attempt of the For loop :slight_smile:

Happy Monday and happy coding :smiley:

Privacy & Terms