I'm working on a madlib program for my class, and I'm trying to code a specific part of the program which will basically repeat the entire program depending on the users input.
#include <iostream>
#include <fstream>
usingnamespace std;
void getFileName(char fileName[]) //Implemented Correctly
{
cout << "Please enter the filename of the Mad Lib: ";
cin.getline(fileName, 256);
return;
}
void playAgain()
{
char yesOrNo;
cout << "Do you want to play again (y/n)? ";
cin >> yesOrNo;
if (yesOrNo == 'n')
{
cout << "Thank you for playing.";
return;
}
if (yesOrNo == 'y')
main();
if (yesOrNo != 'y' || yesOrNo != 'n')
{
cout << "Invalid entry. Do you want to play again (y\n)?";
cin >> yesOrNo;
}
}
int main()
{
char fileName[256];
//char madLibStory[32][256];
getFileName(fileName);
ifstream readFile;
}
I've read before that you should never repeat main, I guess in this case I really don't know what else to do though. As you can see from my playAgain() function, the program asks the user to enter y or no to play again, and depending on that input, it will either end the program, or run it through the entire process again.
My playAgain function works for the no and invalid statements, but the yes statement is doing some funky stuff that I wasn't expecting. What would the "appropriate" way be to go about repeating the entire function?