#include<iostream>
using namespace std;
/*Define an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle */
enum TriangleType {scalene, isosceles, equilateral, noTriangle};
/*
Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle.
*/
TriangleType triangleShape(int l1,int l2,int l3){
if(l1<=0 || l2<=0 || l3<=0){
return noTriangle;
}
if(l1==l2 && l2==l3){
return equilateral;
}
else if(l1==l2 || l1==l3 || l2==l3){
return isosceles;
}
else{
return scalene;
}
}
int main(){
/* Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.
*/
int l1;
int l2;
int l3;
cout<<"Enter first side: ";
cin>>l1;
cout<<"\nEnter second side: ";
cin>>l2;
cout<<"\nEnter third side: ";
cin>>l3;
if(triangleShape(l1,l2,l3)==scalene){
cout<<"The triangle is scalene"<<endl;
}
if(triangleShape(l1,l2,l3)==isosceles){
cout<<"The triangle is isosceles"<<endl;
}
if(triangleShape(l1,l2,l3)==equilateral){
cout<<"The triangle is equilateral"<<endl;
}
if(triangleShape(l1,l2,l3)==noTriangle){
cout<<"It is not a triangle"<<endl;
}
return 0;
}
Comments
Leave a comment