Looks fine but abit of advise try to stay away from side effects,
void GetGuess(){
// get a guess from the player
cout << "What is your guess?: ";
string Guess = “”;
getline(cin, Guess);
//repeat the guess back to them
cout << "Your guess was: " << Guess << endl;
cout << endl;
// get a guess from the player
cout << "What is your guess?: ";
getline(cin, Guess);
//repeat the guess back to them
cout << "Your guess was: " << Guess << endl;
cout << endl;
return;
}
I would istead recommend you to write your functions simpler like following
Remmber that I use the prefix std before every stream related in/ output instead of namespace.
1
2 std::string GetGuess();
3 void ReturnGuess(std::string Guess);
4 int main()
5 {
6/* some code*/
7
8 ReturnGuess(GetGuess());
9
10 return 0;
11 }
12 std::string GetGuess()
13 {
14 std::string Guess;
15 std::cout<<"please enter your guess: ";
16 std::getline(std::cin, Guess);
17 return Guess;
18 }
19
20 void ReturnGuess(std::string Guess)
21 {
22 std::cout << "your guess was: " << Guess << std::endl;
23}
This may be over doing it but it’s good practice. So what’s happening (notice that I excluded the #include from my code just to simplify abit). Okej so first we’re prototyping our functions or (declaring them) then when we come to main I’ve written one line of code which is ReturnGuess(GetGuess()); By doing this I’m getting a Guess from GetGuess() While I’m directly after that returns it via ReturnGuess(string Guess).
If we take a look in GetGuess you can see it’s pretty simple it’s just recives our input and returns it at the end of the function.
std::string GetGuess()
{
std::string Guess;
std::cout<<"please enter your guess: ";
std::getline(std::cin, Guess);
return Guess;
}
Now to be able to read our Guess we ofc need to be able to see it which is why we return our input to our ReturnGuess function. which looks like this.
ReturnGuess(GetGuess());
ReturnGuess on the otherhand looks like this:
void ReturnGuess(std::string Guess)
{
std::cout << "your guess was: " << Guess << std::endl;
}
It’s takes our input and displays it through our output stream.
So I hope a gave you some tips by doing this (not to be mean or anything jsut trying to help you at the start)
And as the above comment said you unfortunately missed #include
Other then me allways over doing things, your code is fine but try stay away from side effects (statements in your function which is not included in the functions name and more).
BTW! doing:
string Guess = “text”;
ReturnGuess(Guess);
is fully acceptable, were just trying to show you another way write simple and “optimized” code