C++ Calculator Skipping Else Statement

后端 未结 4 1020
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 08:07

I was making a simple calculator in C++. However the program does not completely function the way it should. When run, the trig if statement executes fine, however, the basic ar

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-26 08:29

    This line is wrong.

    if(function == "sin" || "cos" || "tan")
    

    It should be

    if((function == "sin") || (function == "cos") || (function == "tan"))
    

    Note that the check is actually meaningless because you already check for them each individually. You could tidy this up by doing this in a if, else if, else chain.

提交回复
热议问题