If/Else 语句在 c++ 中无法正常工作

If/Else statement doesn't work properly in c++

本文关键字:常工作 工作 Else 语句 c++ If      更新时间:2023-10-16

我是一个新手程序员,我在代码中的if/else语句中遇到了问题。 第一个和第二个条件运行良好,但是最后一个else应该返回主输入(输入的n)而不进行任何更改,返回不正确的答案。问题出在哪里?代码为:

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n > 3000000) {
        n = n * 0.9;
        cout << n;
    }
    else if (2000000 < n < 3000000) {
        n = n * 0.95;
        n = n * 0.97;
        cout << n;
    }
    else {
        cout << n;
    }
    return 0;
}

条件定义中的错误:( (n>2000000) && (n<3000000) )