Reputation: 302
This code below does not work no matter if the input is correct or not. If the input is correct, the if statement still executes for some reason. Any quick suggestions would be helpful.
char status;
cout<<"Please enter the customer's status: ";
cin>>status;
if(status != 'P' || 'R')
{
cout<<"\n\nThe customer status code you input does not match one of the choices.\nThe calculations that follow are based on the applicant being a Regular customer."<<endl;
status='R';
}
Upvotes: 0
Views: 120
Reputation: 45410
if ('R')
always evaluates to true, so if(status != 'P' || 'R')
always evaluates to true.
change
if(status != 'P' || 'R')
to
if(status != 'P' && status != 'R')
OR
if(status == 'P' || status == 'R')
The last version may give your clearer view what you want?
Upvotes: 2
Reputation: 21317
It's if(status != 'P' || status != 'R')
.
Even then the logic is kind of off. You can't chain logical OR like that (or any of the logical operators), you should probably use something else like if(status != 'P' && status != 'R')
Upvotes: 3