Beginner here,
Did the challenge but I did it without making a string function and instead made it a void func. After fixing it, I noticed it crashed when “GetGuessAndPrintBack()” was written as a string instead of a void func.
When I say “crash,” I mean after inputting a value after running it, it stops running and Windows reports a crash with its error box.
It is also worth knowing that after the program “crashes” according to Windows, it immediately resumes and continues working.
Posting the entire code so it can be examined.
#include
#include
using namespace std;
void PrintIntro();
void GetGuessAndPrintBack();
//entry point of app
int main() {
PrintIntro();
GetGuessAndPrintBack();
GetGuessAndPrintBack();
return 0;
}
// introdurces game
void PrintIntro() {
constexpr int WORD_LENGTH = 5;
cout << “Welcome to Bulls and Cows, a fun word game.” << endl;
cout << "Can you guess the “;
cout << WORD_LENGTH;
cout << " letter isogram I am thinking of?\n”;
return;
}
//get a guess from player and plays back
void GetGuessAndPrintBack() {
string Guess = “”;
cout << “Input a guess now.\n”;
std::getline(std::cin, Guess);
cout << "Your word is ";
cout << Guess;
cout << “, correct?\n”;
return;
}
Right at the end here, with the GetGuessAndPrintBack(), it crashes if I switch that to a string and introduce it as a string.
What’s the issue?