构造 do while 循环以处理C++不起作用的帐号
Constructing do while loop to handle account numbers not working C++
我正在尝试使用do while循环来评估帐号。有效的帐号必须有 5 位数字,并以字母 R 或 B 开头,不区分大小写。
有效帐号示例:R90000B10101编号: R88888b77777
无效帐号示例:Y90000r888822
这是我做的循环,我无法弄清楚我的参数出了什么问题,导致它一遍又一遍地重复,除了帐号之外。
char accountType;
int accountNum;
cout << "Please enter your account number." <<endl;
cout << ">> ";
cin >> accountType >> accountNum;
cout <<endl;
do
{
cout << "That is not a valid account number. Please enter your account number." <<endl;
cout << ">> ";
cin >> accountType >> accountNum;
cout <<endl;
}while ( (accountNum <= 9999) || (accountNum >= 100000) && (accountType != 'r') || (accountType != 'R') || (accountType != 'b') || (accountType != 'B') );
有什么想法吗?
重复循环的条件是以下任何一项:
-
accountNum <= 9999
-
accountNum >= 100000 && accountType != 'r'
-
accountType != 'R'
-
accountType != 'b'
-
accountType != 'B'
但是对于每个字符,(3)、(4) 和 (5) 中至少有两个是正确的,所以你总是会重复。
您需要在所有accountType
检查失败或任何accountNum
检查失败时进行循环。也就是说,以下任何一项:
-
accountNum <= 9999
-
accountNum >= 100000
-
accountType != 'r' && accountType != 'R' && accountType != 'b' && accountType != 'B'
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- 我正在开发服务器,ip作为参数传递不起作用