Final answer:
To write a C++ program that accepts the lengths of three sides of a triangle as input from the user, you can use the provided code which includes validation for positive side lengths. The program uses conditional statements to determine the type of triangle based on the lengths of the sides, and outputs the corresponding result.
Step-by-step explanation:
To write a C++ program that accepts the lengths of three sides of a triangle as input from the user, you can use the following code:
#include <iostream>
using namespace std;
int main() {
float a, b, c;
cout << "Enter the lengths of the three sides of the triangle: ";
cin >> a >> b >> c;
if (a > 0 && b > 0 && c > 0) {
if (a == b && b == c) {
cout << "The triangle is an Equilateral Triangle." << endl;
} else if (a == b || b == c || a == c) {
cout << "The triangle is an Isosceles which is Not Equilateral triangle." << endl;
} else if ((a * a == b * b + c * c) || (b * b == a * a + c * c) || (c * c == a * a + b * b)) {
cout << "The triangle is a Right triangle." << endl;
} else {
cout << "The triangle is some other type of triangle." << endl;
}
} else {
cout << "Please enter positive values for the lengths of the sides." << endl;
}
return 0;
}
This program prompts the user to enter the lengths of the three sides of a triangle and validates the input to ensure that the lengths are positive. It then uses conditional statements to determine the type of triangle based on the lengths of the sides. The program outputs whether the triangle is an Equilateral Triangle, a Right Triangle, Isosceles which is Not Equilateral, or some other type of triangle.