While loop using !not operator

I don't know how to use my not operator for char B, C, and D
I can only get it to work on one condition

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



#include<iostream>
#include<string>


using namespace std;






int main()
{
    const char size = 20;
    char answers[size];
     
    cout << "Welcome to the written portion of the DMV exam. \n";
    cout << "Please only enter capital A, B, C, or D for your answers.\n\n" << endl;

    for (int index = 0; index < size; index++)
     {
        cout << "Enter your answer for question " << index+1 << endl;
        cin >> answers[index];
     
        while (answers[index] != 'A') 
         {
            cout << "ERROR: you must input capital A,B,C, or D" << endl;
            cin >> answers[index];
        }

    }
    



    system("pause");
     return 0;
}
Last edited on
Rather than showing us what works, please show us what didn't work.

I'm guesing what you want is this:
1
2
3
4
while ( answers[index] != 'A' 
          && answers[index] != 'B'
          && answers[index] != 'C'
          && answers[index] != 'D' )





Oh ok thanks, maybe it didn't work because I kept using the or operator.
I should have known. Thanks nonetheless.
Topic archived. No new replies allowed.