无论输入是否正确,下面的代码都不起作用。如果输入正确,if 语句由于某种原因仍然执行。任何快速建议都会有所帮助。
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';
}
最佳答案
它是 if(status != 'P' || status != 'R')
。
即便如此,逻辑还是有点不对劲。你不能像那样链接逻辑或(或任何逻辑运算符),你可能应该使用其他东西,比如 if(status != 'P' && status != 'R')
关于C++ 简单字符检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14669280/