Clarity is worth fighting for comments

Okay, I did the extract function like we were told and I want to share the code i got. It’s a little different, but it is closer to what he typed afterward than what he said we would probably get. I think my version of VS is a little newer too though, so that may have some influence on that.

    #include "stdafx.h"
    #include <iostream>
    #include <string>

    void PrintIntro();
    void PlayGame(const int &NUM_CHANCES);
    std::string GetGuessAndPrintBack();

    int main()
    {
    	constexpr int NUM_CHANCES = 5;                                         // number of turns per play.

    	PrintIntro();                                                          // Greet the player
    	PlayGame(NUM_CHANCES);                                                 // Play the game
    	
    	return 0;
    }

    void PrintIntro()
    {
    	constexpr int WORD_LENGTH = 5;

    	std::cout << "Welcome to Bulls and Cows\n";
    	std::cout << "Can you guess the " << WORD_LENGTH << " letter isogram I'm thinking of?\n";

    	return;
    }

    void PlayGame(const int &NUM_CHANCES)
    {
    	for (int repeat = 1; repeat <= NUM_CHANCES; repeat++)                  // Give the player NUM_CHANCES amount of turns to guess the word.
    	{
    		GetGuessAndPrintBack();
    	}
    }

    std::string GetGuessAndPrintBack()
    {
    	std::string guess = "";

    	// get a guess from the player
    	std::cout << "\nYour guess: ";
    	std::getline(std::cin, guess);

    	// repeat the guess back to them
    	std::cout << "This is your guess: " << guess << std::endl << std::endl;

    	return guess;
    }

In other words, mine didn’t add a header file. it added it like we wanted it to, so that’s great right? I know my function takes an argument, but i put my variable in a different place, so that’s why, but otherwise it seems to work correctly. Just thought I would share.

Privacy & Terms