-4

I have written this program, it passes all manual test conditions but says "wrong answer" when I submit online on an IDE. Constraints 0≤a,b,c≤180

    #include <iostream>
using namespace std;

int main() {
    // your code goes here
    double a,b,c;
    cin>>a>>b>>c;
    if(a+b+c==180)
    cout<<"YES";
    else
    cout<<"NO";
    
    return 0;
}
Sina
  • 1
  • 1
  • 2
    Have you checked edge cases like `0,0,180`, and we can't use `==` to compare double values for a precision reason: https://stackoverflow.com/questions/588004/is-floating-point-math-broken. – prehistoricpenguin Jun 25 '21 at 02:24
  • Q: Does the program work for you when you build and execute it yourself. Q: Have you considered the fact that "==" is *NOT* a good idea with floating point arithmetic. MOST IMPORTANT: `[it] says "wrong answer" when I submit online on an IDE...`. What the heck does that mean? WHAT "on line IDE"??? Does this IDE give you any clue what it doesn't like? Please clarify... – paulsm4 Jun 25 '21 at 02:28
  • 2
    Input of `-50 230 0` will incorrectly pass your test. – Peter Jun 25 '21 at 02:45
  • 1
    @prehistoricpenguin thanks for the hints I made changes to the logic and it worked. –  Sina Jun 26 '21 at 03:55
  • @Peter you were I added the condition that a,b,c >0 and it's working absolutely fine now –  Sina Jun 26 '21 at 03:56

2 Answers2

-1

The above code doesn't give correct answer when either of a,bc is zero and the a+b+c=180. So,

int main()
{
// your code goes here
double a,b,c;
cin>>a>>b>>c;
//add the below statement
if((a!=0)&&(b!=0)&&(c!=0)){
if(a+b+c==180)
cout<<"YES";
else
cout<<"NO";
}
else{
 cout<<"NO";
}
return 0;
}
Akhila
  • 9
  • 4
-1
int main()
{
// your code goes here
double a,b,c;
cin>>a>>b>>c;
//made the changes with the help of suggestion from the forum
if((a>0)&&(b>0)&&(c>0)&&(a+b+c==180))
cout<<"YES";
else
cout<<"NO";


return 0;
}
Sina
  • 1
  • 1