C++ Program to Check Triangle is Valid using Angles

Write a C++ Program to Check Triangle is Valid using Angles with an example. This C++ program allows users to enter three angles of a triangle and finds the sum of those angles. Next, we used the C++ If Else statement to check whether the sum is equal to 180. If True, it is a valid triangle; otherwise, it’s invalid.

#include<iostream>
using namespace std;

int main()
{
	int angle1, angle2, angle3, sum;
	
	cout << "\nPlease Enter Three Angles of a Triangle =  ";
	cin >> angle1 >> angle2 >> angle3;
	
	sum = angle1 + angle2 + angle3;
	
	if( sum == 180)
  	{
  		cout << "\nThis is a Valid Triangle";
  	}
  	else
    	cout << "\nThis is an Invalid Triangle";
		
 	return 0;
}
Please Enter Three Angles of a Triangle =  30 60  90

This is a Valid Triangle

Let me check with wrong angles of a triangle.

Please Enter Three Angles of a Triangle =  30 90 120

This is an Invalid Triangle

C++ Program to Check Triangle is Valid using Angles Example 2

Apart from the sum of all angles equal to 180, all the angles of the triangle should be non-zeros. In this C++ program, we check the same.

#include<iostream>
using namespace std;

int main()
{
	int angle1, angle2, angle3, sum;
	
	cout << "\nPlease Enter Three Angles of a Triangle =  ";
	cin >> angle1 >> angle2 >> angle3;
	
	sum = angle1 + angle2 + angle3;
	
	if(sum == 180 && angle1 != 0 && angle2 != 0 && angle3 != 0)
  	{
  		cout << "\nThis is a Valid Triangle";
  	}
  	else
    	cout << "\nThis is an Invalid Triangle";
		
 	return 0;
}
C++ Program to Check Triangle is Valid using Angles 3