Write a program that will read in 3 integer line lengths. Determine if you can construct a triangle from these lengths. If you can construct a triangle, is it equilateral, isosceles or scalene? Is it a right triangle?
| Input | Processing | Output |
|---|---|---|
|
3 line lengths
called A, B and C. |
Processing Items
H -hypotenuse
response - reprocess flag
Algorithm:
Start
DO
get A
get B
get C
If input is valid
If input is a triangle
If Equilateral triangle
Print "Equilateral"
Else If Isoceles triangle
Print "Isoceles"
Else
Print "Scalene"
Compute H
If Right triangle
print "Right Triangle"
EndIF
EndIF
EndIf
Else
Print "Not a triangle"
EndIF
Else
Print "invalid input"
EndIf
Prompt "Try Again"
get response
Repeat while (response = "Y")
stop
| triangle status |
[01]//
[02]// Is it a triangle?
[03]//
[04]#include <iostream>
[05]
[06]using namespace std;
[07]
[08]int main()
[09]{
[10] int a,b,c; // three lengths
[11] int h; // length of hypotenuse
[12] char response;
[13]
[14] do {
[15] cout << "Please enter three integer lengths ";
[16] cin >> a >> b >> c;
[17] if(a>0 && b>0 && c>0)
[18] if(a+b>c && b+c>a && a+c>b)
[19] if(a==b && b==c)
[20] cout << "Equilateral Triangle" <<endl;
[21] else if (a==b || a==c || b==c)
[22] cout << "Isoceles Trainagle" << endl;
[23] else {
[24] cout << "Scalene triangle" << endl;
[25] h=a;
[26] if(b>h) h=b;
[27] if(c>h) h=c;
[28] if(a*a+b*b+c*c-h*h == h*h)
[29] cout << "Also a Right Triangle" << endl;
[30] }
[31] else cout << "Not a triangle" << endl;
[32] else cout << "Invalid input" << endl;
[33] cout << "Do you wish to try again?: ";
[34] cin >> response;
[35] } while (response == 'y' || response == 'Y');
[36] system("Pause");
[37] return(0);
[38]}
Please enter three integer lengths 0 0 0 Invalid input Do you wish to try again?: y Please enter three integer lengths 3 3 3 Equilateral Triangle Do you wish to try again?: y Please enter three integer lengths 3 3 5 Isoceles Trainagle Do you wish to try again?: y Please enter three integer lengths 2 4 5 Scalene triangle Do you wish to try again?: y Please enter three integer lengths 5 4 3 Scalene triangle Also a Right Triangle Do you wish to try again?: n Press any key to continue . . .