Operator '&&' cannot be applied to operand of type 'bool' and 'int'

后端 未结 4 1824
庸人自扰
庸人自扰 2021-01-12 10:49

I have an if elseif statement to check marks and grade the marks according to the condition.

int marks;
string grade;

if (marks>=80 && marks!>         


        
4条回答
  •  感情败类
    2021-01-12 11:09

    Other answers have made it known that the main problem is that !> isn't an operator.

    I'd like to suggest that since you're testing whether marks lies within particular ranges that you take an additional further step to format your conditional expressions to use the following pattern:

    if (80 <= marks && marks <= 100)
    {
      grade = "A1";
    }
    else if (70 <= marks && marks <= 79)
    {
      grade = "A2";
    }
    

    It's a simple and maybe subtle change, but I think it makes the range check intent much more clear.

提交回复
热议问题