char returning

i am writing a basic slot machine program and i am stuck on asking the user if they want to play the game. if the user enters N or n, the game is supposed to thank them for playing and end the game. i cant figure out where in the code that would go. any ideas? thank you for any help.

string getname(); //prototype
string getname() //header
{
string name;
getline (cin, name);
return name;
}

char getyorn(); //prototype
char getyorn() //header
{
char response;
cin >> response;
while (response != 'y' && response != 'n' && response != 'Y' && response != 'N')
{
cout << "Please enter a Y or N or y or n ";
cin >> response;
}
return response;
}

int main()
{
cout << "One Armed Bandit!! " << endl;
cout << "What's your name? ";
getname();

cout << "You will start with 200 dollars " << endl;
cout << "Do you want to play with the One Armed Bandit? ";
getyorn();

return 0;
}
Your main game loop should probably be in main. After you have executed all of your functions (one iteration), you then prompt the user if the wish to continue playing. If no, the program ends.

1
2
3
4
5
6
7
8
9
int main()
{
    do
    {
       //... game functions
    }while( answer == 'y' || answer == 'n' );        
    
    return 0;
}
Topic archived. No new replies allowed.