If Statement Not Working

Pages: 12
closed account (48T7M4Gy)
The only thing that I would prefer is when you type in something that causes the error, is for it to tell you then press a key to clear the screen and return to the menu.


That's what I meant with the while loop I mentioned earlier. It was easier to do it than explain in words.

As far as the Error is concerned it does actually show on the screen. Like i said, put in whatever message or programming you want, there is no limitation in principle. And you can place cls's and pause's as required to 'slow things down'. It's all up to you how you want to present your program interface.

Try this and change get_menu_selection to:
1
2
3
4
5
6
7
8
9
10
11
int get_menu_selection()
{
    int selection = 0;
    
    while(cout << "Pls enter a selection: " and cin >> selection and (selection < 1 or selection > 3) )
    {
        cout << " ************************ Error: you'll have to re-enter a selection\n";
        display_Menu();
    }
    return selection;
}

closed account (48T7M4Gy)
it returns to the menu.


All functions return to the line after the line ( in main() in this case ) where they were called from. void functions don't actually need an explicit return but I put it in to make sure you could see what was going on. Leave it out in any void function and the same will happen because the return is there implicitly. (It renders down to a more useable and friendly goto or jump, believe it or not and that's more or less why you'll rarely need a goto statement.)
Topic archived. No new replies allowed.
Pages: 12