C++ 简单字符检查

标签 c++ .net visual-studio visual-c++ char

无论输入是否正确,下面的代码都不起作用。如果输入正确,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/

相关文章:

.net - 如何将特定类型的数组存储到我的设置文件中?

c# - WPF 自定义词典仅在 Windows 10 上的 %TEMP% 中创建 .dict 文件

c++ - C 忽略增量

c++ - Qt 5.7 如何在运行时检查变量 QT_QPA_PLATFORM 的值?

c++ - 相同的地址被存储在链表的头部

c++ - Qt5 应用程序不会在 Ubuntu 上绘制任何窗口

c# - 哪种方法可以更好地阻止 sql 注入(inject)

visual-studio - CGAL - 构建安装 .sln,错误 MSB3073 : The command "setlocal"

visual-studio - 如何解决 Visual Studio 中的长构建问题?

c++ - 为什么 Boost Log 记录器操作不是常量?