Help please, Need a small fix

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nomana123
    New Member
    • Oct 2008
    • 7

    Help please, Need a small fix

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {//variables defined here
    float angle,q;
    
    cout<<"Enter angle value ";
    cin>>angle;
    
    if (angle==0)
    {cout<<"This angle is zero";
    }
    else if (angle>0&&angle<90)
    {cout<<"This is an acute angle";
    }
    else if (angle=90)
    {cout<<"This is a right angle";
    }
    else if (angle>90&&angle=<180)
    {cout<<"This is an obtuse angle";
    }
    else if (angle<0)
    {cout<<"This angle will not work";
    }
    cout<<"\nPress Q to quit";
    cin>>q;
    }
    Enter angle value 180
    This is a right angle
    Press Q to quit

    for 180 i'm getting as a right angle.
    and for 95 as well.
    Enter angle value 95
    This is a right angle
    Press Q to quit
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    This line
    else if (angle=90)
    will assign the value 90 to angle and then check to see whether 90 is true. It is. Try using the == comparison operator instead.
    else if (angle==90)
    You'll need to fix this in other places as well.
    Hope this helps.

    Comment

    • nomana123
      New Member
      • Oct 2008
      • 7

      #3
      yep worked like a charm, thank you.

      Comment

      Working...