gpt4 book ai didi

c++ - 构造 do while 循环来处理帐号不工作 C++

转载 作者:行者123 更新时间:2023-11-28 02:10:56 26 4
gpt4 key购买 nike

我正在尝试使用 do while 循环来评估帐号。有效的帐号必须有 5 位数字,并以字母 R 或 B 开头,不区分大小写。

有效帐号示例:r90000B10101R88888b77777

无效帐号示例: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') );

有什么想法吗?

最佳答案

重复循环的条件是任何:

  1. accountNum <= 9999
  2. accountNum >= 100000 && accountType != 'r'
  3. accountType != 'R'
  4. accountType != 'b'
  5. accountType != 'B'

但是对于每个 字符,(3)、(4) 和(5) 中至少有两个为真,因此您将始终重复。

您需要循环 while 所有 accountType检查失败或任何 accountNum检查失败。也就是说,任何:

  1. accountNum <= 9999
  2. accountNum >= 100000
  3. accountType != 'r' && accountType != 'R' && accountType != 'b' && accountType != 'B'

关于c++ - 构造 do while 循环来处理帐号不工作 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35691519/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com