Question
help im alittle lost my teacher posted all this its suppose to be in C++ language.
can yoh leave comments ans type the code thank you
Write a C++ program that accepts the lengths of three sides (a,b,c) of a triangle as input from the user Validate the user in

Hints: 1) VALIDATE the user input so that the user can only enter positive values. Keep in mind that the user can be very dum

Sample Run: Please enter side A: 1 Please enter Side B: -10 Value entered must be positive! Please enter side B: -100 Value e
Please enter side A: 3 Please enter side B: 4 Please enter side C: 5 This is an RIGHT triangle. Would you like to repeat (1-Y
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the required C++ program for the same. Write a comment if you have any queries. Thanks!
______________________________________________________________________________

#include <iostream>

using namespace std;

//method to check the type of triangle

string check_type( int arr[] ){

  

                string type = "";

                int a=arr[0], b=arr[1], c=arr[2];

               

                if( a==b && b==c ){

                                type = "EQUILATERAL triangle! (all sides are equal)";

                }

                else if( a==b || b==c || a==c ){

                                type = "ISOSCELES triangle, where only two sides are equal";

                }

                else if( ((a^2+b^2)==(c^2)) || ((a^2+c^2) ==(b^2)) || ((b^2+c^2) ==(a^2)) ){

                                type = "RIGHT triangle";

                }

                else{

                                type = "OTHER kind of triangle, NOT ISOSCELES, NOT RIGHT and NOT EQUILATERAL";

                }

               

                return type;

}

int main(){

                string side_name[3] = {"A","B","C"}; //storing side names A B C

                int side_value[3]; //side values

                int choice=1; //by default you want to check for the first time

               

                do{

                for(int i=0; i<3; i++){

                                cout<<"Please enter side "<<side_name[i]<<": ";

                                cin>>side_value[i];

                               

                                if( side_value[i] <= 0 ){

                                                cout<<"Value entered must be positive!\n";

                                                i--;

                                }

                }

                               

                cout<<"This is an "<<check_type(side_value);

               

                cout<<"\nWould you like to repeat(1-Yes,2-No): ";

                cin>>choice;

                }while(choice == 1);

               

                return 1;

}

_______________________________________________________________

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
help im alittle lost my teacher posted all this its suppose to be in C++ language....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP...

    PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here    do { // program here             }while (true);    } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...

  • //////// ONLY JAVA **** //////// ONLY JAVA **** 5. In a right triangle, the square of...

    //////// ONLY JAVA **** //////// ONLY JAVA **** 5. In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. (Have the user enter the lengths 3, 4, and 5).

  • Java Please - Design and implement a class Triangle. A constructor should accept the lengths of...

    Java Please - Design and implement a class Triangle. A constructor should accept the lengths of a triangle’s 3 sides (as integers) and verify that the sum of any 2 sides is greater than the 3rd(i.e., that the 3 sides satisfy the triangle inequality). The constructor should mark the triangle as valid or invalid; do not throw an exception. Provide get and set methods for the 3 sides, and recheck for validity in the set methods. Provide a toString method...

  • Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3:...

    Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...

  • In C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for...

    In C program #include<stdio.h> Task is to implement the Triangle Program in C. The specification for the program is: The triangle program accepts three strings, a, b, and c (the sides of a triangle) as command line parameters. The sides of the triangle must be integers. The sides a, b, and c must satisfy the following conditions: c1. 1 ≤ a ≤ 200 c2. 1 ≤ b ≤ 200 c3. 1 ≤ c ≤ 200 c4. a < b +...

  • (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore,...

    (JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...

  • C code. Write a program to find all the triangles with integer side lengths and a...

    C code. Write a program to find all the triangles with integer side lengths and a user specified perimeter. Perimeter is the sum of all the sides of the triangle. Integers a, b and c form a triangle if the sum of the lengths of any two sides is greater than the third side. Your program should find all the triples a, b and c where a + b + c is user specified perimeter value. Print each triple only...

  • In a right triangle, the square of the length of one side is equal to the...

    In a right triangle, the square of the length of one side is equal to the sum of the squares of the lengths of the other two sides. Write a program that prompts the user to enter the lengths of three sides of a triangle and then outputs a message indicating whether the triangle is a right triangle. If the triangle is a right triangle, output It is a right-angled triangle If the triangle is not a right triangle, output...

  • Consider again the triangle classification program with a slightly different specification: The program reads floating values...

    Consider again the triangle classification program with a slightly different specification: The program reads floating values from the standard input. The three values A, B, and C are interpreted as representing the lengths of the sides of a triangle. The program then prints a message to the standard output that states whether the triangle, if it can be formed, is scalene, isosceles, equilateral, or right angled. Determine the following for the above program: Part a: For the boundary condition A+B>Ccase...

  • ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same...

    ***IN PYTHON: Scalene triangle: All sides have different lengths Isosceles triangle: Two sides have the same length Equilateral triangle: All sides are equal Write a program to ask for the length of 3 sides a, b and c. Ask for three sides at a time Determine the type of triangle given three sides Handle all kinds of errors - 1. not integers, int() conversion fails 2. not enough args, 3. too many arguments HINT: use the len() function to check...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT