//
#include <iostream>
using namespace std;
#include <cmath>
#include <math.h>
int main()
{
float a, b, c, t, s, area;
cout << "Enter the lengths of your triangle's sides: ";
cin >> a >> b >> c;
if(a>b) {t=a; a=b; b=t;};
if(b>c) {t=b; b=c; c=t;};
if(a>b) {t=a; a=b; b=t;};
if((c*c) < (a*a)+(b*b))
cout << "Your triangle is an acute ";
else
if((c*c) == (a*a)+(b*b))
cout << "Your triangle is a right ";
else
if((c*c) > (a*a)+(b*b))
cout << "Your triangle is an obtuse ";
if(a==b&&b==c)
cout << "equilateral triangle.";
else
if(a!=b&&b!=c&&c!=a)
cout << "scalene triangle.";
else
if(a==b&&b!=c||b==c&&b!=a)
cout << "isosceles triangle." << endl;
s = ((a+b+c) / 2);
area = sqrt(s * (s-a) * (s-b) * (s-c));
cout << " The area of the triangle is " << area << endl;
system ("pause");
}
How would I make this program output an error message and exit the program if the user inputs a letter instead of a number or if the user inputs three lengths that do not create a triangle?
I have tried this for the inputs that do not create a triangle
if(a+b<c)
cout << "Your lengths do not create a triangle" << endl;
exit(EXIT_FAILURE);
but it closes the program even if the inputs were valid.