Still stumped

Hello... This still has got me stumped. Is there a way to cin check the options made available. For instance, if something other than V,A,G or Q is entered it will give an invalid input message and request to re-enter a valid option? Below is the piece of code in question. Thank you in advance



#include <iostream>
#include <iomanip>

using namespace std;

const char q = 'Q';
int main()
{
char option = ' ';
float volume, area, girth, length, width, depth;
option = tolower(option); // converts option input to lower case

while (option != q)
{
cout<< "To determine Volume, enter V \n"
<< "To determine Surface Area, enter A \n"
<< "To determine Girth, enter G \n"
<< "To quit, enter Q\n"
<< "Selection: ";
cin >> option;

if (option == 'q' || option == 'Q')
break;
1
2
3
4
5
6
cin >> option;
while (option != 'v' && option != 'a' && option != 'g' && option != 'q')
{
  cout << "Option is not acceptable letter";
 cin >> option;
}
Last edited on
closed account (zb0S216C)
It's easily achieved:

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

for( ; ( ( option != 'q' ) || ( option != 'Q' ) ); )
{
    switch( option )
    {
        case 'A':
        case 'a':
            // Something.
            break;

        case 'G':
        case 'g':
            // Something.
            break;

        case 'V':
        case 'v':
            // Something
            break;

        case 'Q':
        case 'q':
            // Something.
            break;

        default:
            // Invalid input.
            break;
    }
}


No?

Wazzak
Last edited on
Topic archived. No new replies allowed.