gpt4 book ai didi

c++ - 如何在 while 语句中设置多个条件? (c++)

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:10:53 25 4
gpt4 key购买 nike

while 语句中可以有三个条件吗?

例如:

cout << "\n\nHow would you like your parcel shipped?\n (please type standard, express"
" or same day)" << endl;
cin >> method;
while (method != ("standard" && "express" && "same day"))
{
cout << "invalid input: please follow the instructions carefully.." << endl;
cout << "\n\nHow would you like your parcel shipped?\n (please type 'standard',"
" 'express' or 'same day')" << endl;
cin >> method;
}

我问的原因是当我运行这段代码时,它进入了一个无限循环,我无法理解为什么。

最佳答案

while (method != "standard" && method != "express" && method != "same day")

关于c++ - 如何在 while 语句中设置多个条件? (c++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27891417/

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