How do I use the or "||" operator with a Char type in a loop?

I am trying to make this loop until a valid char is entered.
1
2
3
4
5
6
7
8
9
10
11
12
13

while ( VALID =1)
{
 cout << "Enter customer type: " 
 << "R or r (Regular), "
 << "P or p (Premium):  ";                 
 cin >>  customerType;
	if ( (customerType = 'R') || (customerType = 'r') ||(customerType = 'P') || (customerType = 'p') )
	 VALID = 0
 else
	VALID = 1;
}
Last edited on
Besides your other syntax errors you need to use == for comparison, not =.
It is better to use the loop do-while

1
2
3
4
5
6
7
8
9
do
{
   cout << "Enter customer type: " 
          << "R or r (Regular), "
          << "P or p (Premium):  ";                 

   cin >>  customerType;
} while ( toupper( customerType ) != 'R' && toupper( customerType ) != 'P' );
    
Last edited on
Exactly what I needed. I am taking basic C++ right now so the toupper was very helpful. Thank you for your help!
Topic archived. No new replies allowed.