C++ Program to Check if Triangle is Valid or Not using Angles

Write C++ Program to Check if Triangle is Valid or Not using Angles

// CPP Program to Check if Triangle is Valid or Not using Angles

#include <iostream>

using namespace std;

int main()
{
    int angle1, angle2, angle3, total;

    cout << "Enter Angle 1 :--> ";
    cin >> angle1;

    cout << "Enter Angle 2 :--> ";
    cin >> angle2;

    cout << "Enter Angle 3 :--> ";
    cin >> angle3;

    total = angle1 + angle2 + angle3 ;
    printf("\nSum of Angles :--> %d\n", total);
    if( total == 180)
	{
        cout << "Sum of angle is 180, so It is a Valid Triangle";
    }
	else
	{
        cout << "Sum of Angle is not 180, so, It is an invalid Triangle";
    }

    return 0;
}

Output:

Run - 1:
Enter Angle 1 :--> 50
Enter Angle 2 :--> 60
Enter Angle 3 :--> 70

Sum of Angles :--> 180
Sum of angle is 180, so It is a Valid Triangle

Run - 2:
Enter Angle 1 :--> 40
Enter Angle 2 :--> 50
Enter Angle 3 :--> 60

Sum of Angles :--> 150
Sum of Angle is not 180, so, It is an invalid Triangle

≪ Previous | Next ≫