Question regarding good coding practice

My solution was slightly different:

I moved PrintBack into it’s own method and declared the string Guess at the top outside of any methods.

Is this any type of back coding practice which will come back to haunt me later when I get more into C++?

Matt.

Yeah I also did the same thing, and I’m wondering if it is considered a bad coding practice.

I did something similar except my Print function has a string that = GetGuess() within it that it then returns.
I feel that it feels wrong but I’m curious as I would like to try and keep everything within functions and out of main.

I did the same thing; but I’m wondering if something like
string PrintGuess(Guess) should be placed in at least one location in the code.

I’m actually surprised that the code works. You declare your variable for Guess in your function for GetGuess() so the scope of that variable is limited to that function. That’s why in the video; Ben declares another variable Guess in PlayGame() because the variable he had in his statement cout<<"…"<<Guess was not declared anymore

In yours, not only do you not declare a new variable in PlayGame but your function PrintGuess() is somehow getting the Guess variable even though you left the parameters blank.

i.e. the expected code in PlayGame() was:
string Guess = GetGuess();
PrintGuess(Guess)

You grab the variable in function GetGuess() and send it to function PrintGuess().

Privacy & Terms