Answer the question
In order to leave comments, you need to log in
What mistakes did I make in the code?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double a,b,c,x,y,z;
cin>>a>>b>>c;
x=(b*b+c*c-a*a)/(2*b*c);
y=(a*a+c*c-b*b)/(2*a*c);
z=(a*a+b*b-c*c)/(2*a*b);
if (x&&y&&z<0)
{
cout<<"acute";
}
else if (x||y||z==0)
{
cout<<"rect";
}
else if (x||y||z>0)
{
cout<<"obtuse";
}
else
{
cout<<"impossible";
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
1. Acute - when all cosines are less than zero?? vice versa - when everything is greater than zero
2. Impossible - check for a triangle inequality (or the same in essence - that all cosines < 1 modulo)
3. Well, learn to write the conditions:
x&&y&&z<0 -> x<0 && y<0 &&z<0
x||y||z==0 -> x==0 || y==0 || z==0
From a C++ point of view, there are no errors. The program should assemble and work.
But she doesn't seem to get the job done right.
The algorithm for solving the problem is googled in 10 seconds. It is also not difficult to find a condition for the possibility of constructing a triangle on given sides.
Apparently, the conditions in the if you have written incorrectly. From the point of view of the language, they are correct, but they most likely do not what you want. And you can only guess what you want.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question