So I've been following some tutorials on Udemy for C++ and so far it's been incredibly informative and clear however I'm a little stumped by how a for function is calling another function.
So my first function is;
EDIT I've included use namespace std so being the String rather than std::
string getGuess()
{
cout << "Enter your guess" << endl;
Guess = "";
getLine(cin,Guess);
cout << "Your guess was: " << Guess << endl;
return Guess;
}
And then to iterate through this function 5 times so they can guess 5 times I'm writing
void play()
{
constexpr int guessTimes = 5;
for(int i = 0; i<=guessTimes ; i++)
{
getGuess();
}
}
Now this all makes sense to me, however the next part of the tutorial is abstracting the;
cout << "Your guess was: " << Guess << endl;
The for function is then rewritten as so;
void play()
{
constexpr int guessTimes = 5;
for(int i = 0; i<=guessTimes ; i++)
{
string Guess = getGuess();
cout << "Your guess was: " << Guess << endl;
cout << endl;
}
}
I don't quite understand how it's now running the getGuess function as it's now applied to a new String variable which in itself I find quite strange, some clarification of how the fundamentals of this process works would be highly appreciated.