C++简单的字符检查
C++ Simple Char Check
无论
输入是否正确,下面的代码都不起作用。 如果输入正确,则由于某种原因,if 语句仍会执行。 任何快速建议都会有所帮助。
char status;
cout<<"Please enter the customer's status: ";
cin>>status;
if(status != 'P' || 'R')
{
cout<<"nnThe 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')
if ('R')
计算结果始终为 true,因此if(status != 'P' || 'R')
的计算结果始终为 true。
改变
if(status != 'P' || 'R')
自
if(status != 'P' && status != 'R')
或
if(status == 'P' || status == 'R')
最后一个版本可能会让您更清楚地看到您想要什么?
相关文章:
- 在做一段时间内检查字符的无限循环
- 在编译时检查字符的唯一性
- 如何使用C 在.TEXT文件中检查字符序列
- 如何检查字符常量是否符合ASCII
- 错误 ~ 检查字符是否为小写字母
- C++ 使用 || 检查字符是否不在字符串中不工作
- 使用特定格式检查字符数组值
- 如何检查字符是否是某个字母表中的字母
- 检查字符是否等于 C++ 中的
- 如何检查字符是否在范围内
- 如何使用嵌套的 if 语句检查字符数组
- 检查字符中的空白和字符串中的数字
- 如何在c++中检查字符的unicode值的范围
- 检查字符数组的所有元素
- C++ 如何使用 _getch() 实时检查字符
- 检查 字符,但之后不检查
- 检查字符是否为换行符
- 检查字符设备
- 检查字符是否为单引号.c++
- 如何检查字符是否在给定的字符范围内