input validation

i need help with my program please. i have to use the while loop in order to validate the problem.

this is what i have so far, im not quite sure what to do next. im stuck.
any help would be great.

1
2
3
4
5
6
7
8
9
10
  
 char capital = 'Y',
            capital = 'X';
    char lower = 'y', 'x';
    char letter;
    
    cout <<"enter capital/lower case Y or X";
    cin >> letter;
    
    while ( letter)
use this instead:
1
2
3
4
5
6
7
char input = 0;
while ( input != 'Y' && input != 'X' && 
        input != 'y' && input != 'x' )
{
  cout << "enter capital/lower case Y or X";
  cin >> letter;
}


or:

1
2
3
4
5
6
char input = 0;
while ( toupper(input) != 'Y' && toupper(input) != 'X' )
{
  cout << "enter capital/lower case Y or X";
  cin >> letter;
}
Last edited on
i always get confused with the " !=" operator. would you mind explaining to me whats going on here?
The '!=' operator is the "not equal" operator. Basically, what is happening is this:
while (input is not equal to 'x' AND input is not equal to 'y')
enter the input


Except he has used the toupper function to capitalize the input, so you don't have to check for both lowercase and uppercase characters.
Last edited on
Topic archived. No new replies allowed.