Answer to Question #265313 in C++ for Usama

Question #265313

 Write a program that prompts the user to input the length of the sides of a triangle and outputs 

the shape of the triangle.


1
Expert's answer
2021-11-13T01:38:36-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS