While loop trouble

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void PrintMenu(void)
{
    cout <<"+---------Menu---------+" << endl;
    cout << "|Store(s)" << endl;
    cout << "|Exit(e)" << endl;
    cout << "+----------------------+" << endl;
}

int main()
{
    bool RunGame;
    bool MenuError;
    char MenuChoice;

    while (RunGame == true)
    {
        while (MenuError == true)
        {
            PrintMenu();
            cout << "What would you like to do?: ";
            cin >> MenuChoice;

            if (MenuChoice == 's')
            {
                cout << "go to store" << endl;
            }
            else if (MenuChoice == 'e')
            {
                RunGame = false;
            }
            else
            {
                MenuError = true;
                cout << "\nenter a valid choice" << endl;
            }
            return MenuChoice, MenuError, RunGame;
        }


    }


    return 0;
}

When i input something besides 's' or 'e' it outputs "eneter a valid choice" but ends the program after when i want it to ask again till a valid input is entered.
return menuchoice, menu.......

return will exit the current function which is MAIN

btw, you can only return one variable.

u cannot do return var,var1,var2.

another thing is it says INT MAIN()

menuchoice bool

menuerror bool

rungame is char.... u have to return Int.... thus INT MAIN() the int in front of main means u are going to return an integer.
Topic archived. No new replies allowed.