Sign in to follow this  

Prompt user for three sides of triangle and determine if it is valid triangle and then compute area

Recommended Posts

using namespace std;

int main(){

    float aside, bside, cside;
    //enter side a
    cout << "enter the length of side a " << endl;
    cin >> aside;
    //enter side b
    cout << "enter the length of side b " << endl;
    cin >> bside;
    //enter side c
    cout << "enter the length of side c " << endl;
    cin >> cside;

    if (aside == bside && bside == cside) // all sides equal
        cout << "Equilateral triangle\n";
    else if (aside == bside || aside == cside || bside == cside) // at least 2 sides equal
        cout << "Isosceles triangle\n";
    else // no sides equal
        cout << "Scalene triangle\n";

    float first, second, third;
    float s, area;
    cout << endl << "Enter size of each sides of triangle" << endl;
    cout << "Enter size for First Side =";
    cin >> first;
    cout << "Enter size for Second Side =";
    cin >> second;
    cout << "Enter size for Third Side =";
    cin >> third;
    s = (first + second + third) / 2;
    area = sqrt(s*(s - first)*(s - second)*(s - third));
    cout << "Area of Triangle= " << area << endl;

    return 0;

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this