Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have to write a code for my comp sci class and I\'m having trouble with some i

ID: 3624354 • Letter: I

Question

I have to write a code for my comp sci class and I'm having trouble with some instructions given for my assignment. In my assignment we have to input three initials and length of three sides of a triangle. We have to determine if the entered sides form a valid triangle and I'm kind of having trouble with how to write out the calculation part. It states that the triangle must not have negative sides and the sum of any two sides must be greater than the third side to form a triangle. For this part would we write the codes like this... lets say side1, side2, side3 are my declaring variables for the sides so is it ok if I write my code like this (side1 + side2 >= side3)?

The assignment also states to determine if the entered sides are part of a scalene, isosceles, or equilateral triangle and using the pythagorean theorem determine if the isosceles triangle or scalene are right angles. How would the code be using pythagorean theorem.

Any help would be grateful thanks

Explanation / Answer

I don't explain much beforehand but I commented the code plenty, please run it and check for possible syntax slip-ups as I don't have the right compiler on this machine :)
I assumed you have the full code already so this is just the part where we've already obtained the lengths and our algorithm starts - caerful with all the indending - preserve that when you cpoy this code to make it more readable
=============================================================================

/*Only do work if all three sides are positive non-zero values*/
    if((len1 > 0) && (len2 > 0) && (len3 > 0))
    {
        /*Next we check if the triangle inequality property is respected*/
        if( (len1+len2 > len3) && (len2+len3 > len1) && (len1+len3 > len2))
        {
            /*Next we check for special triangles - Isosceles or Equilaterals*/
            if((len1 == len2) || (len2 == len3) || (len3 == len1))
            {
                /*Check for special case of Isosceles ALL lenths are equal*/
                if((len1 == len2) && (len2 == len3) && (len3 == len1))
                {
                    cout << "This is an Equilateral Triangle.";
                }
                /*Otherwise it's just a regular Isosceles*/
                else
                {
                    cout << "This is an Isosceles Triangle";
                    /*Next we check for right angles in Isoceles*/
                    /* applying pythagorean here as    (a*a + b*b = c*c) */
                    if( (len1*len1 + len2*len2 = len3*len3) || (len1*len1 + len3*len3 = len2*len2) || (len3*len3 + len2*len2 = len1*len1))
                    {
                        cout << "This Isosceles Triangle has a right angle.";
                    }
                }
            }
            /*If neither of the 3 sides are equal pairs then this is a regular triangle*/
            else
            {
                cout << "This is a Scalene Triangle";
                /*Next we check for right angles in Scalenes*/
                /* applying pythagorean here as    (a*a + b*b = c*c)      */
                if( (len1*len1 + len2*len2 = len3*len3) || (len1*len1 + len3*len3 = len2*len2) || (len3*len3 + len2*len2 = len1*len1))
                {
                    cout << "This Scalenes Triangle has a right angle.";
                }
            }
        }
        /*Otherwise we print an inequality error message */
        else
        {
            cout << "A triangle's three sides must respect the triangle inequality.";
        }
    }
    /*Otherwise print a negatiev-sides error message*/
    else
    {
        cout << "A triangle needs to have 3 sides of non-negative length.";
    }