gpt4 book ai didi

c++ - if 语句不适用于 || (或者)

转载 作者:太空宇宙 更新时间:2023-11-04 15:04:29 24 4
gpt4 key购买 nike

我是 C++ 新手我试图写一个程序,但我发现了一个问题即使在我使用了一个更简单的程序(下面)之后我也无法弄明白

当我输入诸如 85 或 55 之类的数字时,即使程序不应该响应,它也会响应

#include "stdafx.h"
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int a=0;
cin >> a;
if(a<25 || 30<a<50 || 60<a<75)
{
cout << "see it does't work\n";
}
return 0;
}

请帮帮我

最佳答案

#include "stdafx.h"
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
int a=0;
cin >> a;
if(a<25 || (30<a && a<50) || (60<a && a<75))
{
cout << "see it does't work\n";
}
return 0;
}

关于c++ - if 语句不适用于 || (或者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20085392/

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