Simplifying a menu

The following works, but I just don't know how to make that simpler. I guess I could just have - if staff_or_client is equal to S or s then do the following, else do the following, but that wouldn't work if someone typed in a random letter, it should really cause an error to be more precise.

This is just starting to look a bit elongated. Can anyone think of an easier way?

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
do {
    cout << "Please enter whether you are [S]taff or are a new [C]lient:" << endl;
    cin >> staff_or_client;
    

    
    if (staff_or_client == 'S' || staff_or_client == 's')
    {
        cout << "Welcome staff"<< endl;
        loop_restart == 'a'
    }
    
    
    else if (staff_or_client == 'C' || staff_or_client == 'c')
    {
        cout << "Welcome client" << endl;
        loop_restart == 'a'
    }
    
    else 
    {
        system("CLS");
        cout << "Please re-enter a correct letter to continue" << endl;
        loop_restart == 'a'
    }
}while (loop_restart == 'a');

Last edited on
well you could use a switch statement instead of several ifs and elses, and you could also use the toupper() or tolower() functions and just convert the char to upper or lower case so you wouldn't have to check for 'S' and 's' for example
Last edited on
Good point, will switch to a case statement, makes it much easier, thanks :)
Topic archived. No new replies allowed.