Types of Triangles Based on Angles in c++

To determine the type of triangle based on its angles in C++, you can follow these steps:

  1. Create a C++ program and include the necessary header files. cpp #include <iostream> using namespace std;

  2. Define a function to determine the type of triangle based on its angles. cpp string determineTriangleType(int angle1, int angle2, int angle3) { string triangleType; if (angle1 + angle2 + angle3 == 180) { if (angle1 == 60 && angle2 == 60 && angle3 == 60) { triangleType = "Equilateral Triangle"; } else if (angle1 == angle2 || angle2 == angle3 || angle1 == angle3) { triangleType = "Isosceles Triangle"; } else { triangleType = "Scalene Triangle"; } } else { triangleType = "Not a Triangle"; } return triangleType; }

  3. In the main function, prompt the user to enter the three angles of the triangle. cpp int main() { int angle1, angle2, angle3; cout << "Enter the three angles of the triangle: "; cin >> angle1 >> angle2 >> angle3;

  4. Call the determineTriangleType function passing the entered angles as arguments and store the returned type in a variable. cpp string type = determineTriangleType(angle1, angle2, angle3);

  5. Display the type of triangle based on the returned value. cpp cout << "Triangle Type: " << type << endl;

  6. Close the main function and the program. cpp return 0; }

This program will prompt the user to enter the three angles of a triangle and determine its type based on the angles. The types of triangles considered in this program are Equilateral Triangle, Isosceles Triangle, Scalene Triangle, and Not a Triangle.