Write a program that prompts the user to input the length of the sides of a triangle and outputs
the shape of the triangle.
#include<iostream>
using namespace std;
string getShape(int s1,int s2,int s3){
if(s1<=0 || s2<=0 || s3<=0){
return "noTriangle";
}
if(s1==s2 && s2==s3){
return "equilateral";
}
else if(s1==s2 || s1==s3 || s2==s3){
return "isosceles";
}
else{
return "scalene";
}
}
int main(){
int side1,side2,side3;
cout<<"Enter first side: ";
cin>>side1;
cout<<"\nEnter second side: ";
cin>>side2;
cout<<"\nEnter third side: ";
cin>>side3;
if(getShape(side1,side2,side3)=="scalene"){
cout<<"The triangle is scalene"<<endl;
}
if(getShape(side1,side2,side3)=="isosceles"){
cout<<"The triangle is isosceles"<<endl;
}
if(getShape(side1,side2,side3)=="equilateral"){
cout<<"The triangle is equilateral"<<endl;
}
if(getShape(side1,side2,side3)=="noTriangle"){
cout<<"It is not a triangle"<<endl;
}
return 0;
}
Comments
Leave a comment