Your “PrintIntro ()” function should be implemented BEFORE “int main ()” function.
“int main ()” function is searching for “void PrintIntro ()” function, that is implemented
below it, so when “int main ()” is compiling, “voind PrintIntro()” does not exist yet!
Put function “int main ()” last!
EDIT:
I just wanted to add that you can avoid this problem with
declaring “void PrintIntro()” and “GetGuessAndPrinBack ()”
functions before “int main()”.
This way compiler knows that it should expect those functions (that they exist), and you can implement them AFTER “int main ()”.
#include <iostream>
#include <string>
using namespace std;
/*DECLARING FUNCTIONS (you just tell compiler they exist)
be careful, you put SEMICOLON after! */
void PrintIntro();
string GetGuessAndPrintBack();
//int main function
int main()
{
PrintIntro();
for (int i = 0; i < 4; i++)
{
GetGuessAndPrintBack();
}
return 0;
}
//IMPLEMENTATION OF DECLARED FUNCTIONS ABOVE
void PrintIntro()
{
constexpr int World_Length = 9;
cout << "Welcome to bulls and cows\n";
cout << "Can you guess the " << World_Length;
cout << " the letter isogram im thinking of ?\n";
cout << endl;
}
string GetGuessAndPrintBack() {
//get a guess from the player
cout << "Enter your Guess:";
string Guess = "";
getline(cin, Guess);
//Repeat the guess back to them
cout << "Your Guess was:" << Guess << endl;
cout << endl;
return Guess;
}
