#include <iostream>
usingnamespace std;
int main()
{
cout << "This program determines types of triangles." << endl
<< "Enter the lengths of each side of the triangle" << endl
<< "and the program will determine what type of triangle it is." << endl << endl;
double a;
double b;
double c;
cout << "Length of side a: ";
cin >> a;
cout << "Length of side b: ";
cin >> b;
cout << "Length of side c: ";
cin >> c;
if ((a == b && b == c && a == c)) {
cout << "This is an equilateral triangle." << endl;
}
elseif((a != b && b != c) || (b != c && c != a) || (a != c && c != b))
{
cout << "This is an obtuse scalene triangle." << endl;
}
else {
cout << "This is an acute scalene triangle." << endl;
}
elseif (a + b == c) {
cout << "This is a right triangle." << endl;
}
elseif (a == b && b == c && c != a) {
cout << "This is an isosceles triangle." << endl;
}
if ((a + b >= c) || (a + c >= b) || (b + c >= a))
cout << "Those lengths do not form a triangle." << endl;
}
How would I work out the angles? (to tell the truth, this is to debug)
EDIT: OK, so, I started from scratch. Here is the code below- whenever it should be printing that the legs do not from a triangle it also prints the code for obtuse scalene, and also, how do I do the acute scalene? (very important)
#include <iostream>
usingnamespace std;
int main()
{
cout << "This program determines types of triangles." << endl
<< "Enter the lengths of each side of the triangle" << endl
<< "and the program will determine what type of triangle it is." << endl << endl;
double a;
double b;
double c;
cout << "Length of side a: ";
cin >> a;
cout << "Length of side b: ";
cin >> b;
cout << "Length of side c: ";
cin >> c;
if (a == b && b != c || a == c && b != c)
cout << "This is an isosceles triangle." << endl;
elseif (a == b && b == c && a == c) {
cout << "This is an equilateral triangle." << endl;
}
if((a != b && c) && (b != c && a) && (a != c && b))
cout << "This is an obtuse scalene triangle." << endl;
if (a*a + b*b == c*c)
cout << "This is a right triangle." << endl;
elseif ((a + b > c) || (a + c > b) || (b + c > a))
cout << "Those lengths do not form a triangle." << endl;
}
You can do this without the angles by using the Pythagorean Theorem.
1. Check to see if the triangle is possible given the side-lengths (you currently have this as the last check)
2. Check to see if the triange is an equilateral triangle.
3. Check to see if the triangle is an isosceles triangle.
4. If the triangle is possible but not equilateral or isosceles, you have a scalene triangle.
To check whether an isosceles or scalene triangle is acute, right, or obtuse, find the longest side given to you and treat it as the hypotenuse c. Call the other sides a and b (or whatever variable names you prefer).
a2 + b2 = c2 : right triange
a2 + b2 < c2 : obtuse triange
a2 + b2 > c2 : acute triange