//Given the lengths of three sides of a triangle, this program prints whether the triangle is a right triangle, using the Pythagorean theorem. It doesn't assume that the sides are entered in a specific order.
#include<iostream>
using namespace std;
//Function: InputLengths
//Get the three numbers
//Precondition: None
//Postcondiction: Three values, the sides
void InputLengths (double & len1, double & len2, double & len3);
//Function: PythagThmCheck
//Ask if the sides make up a right angle
//Precondition: Three values, the sides
//Postcondiction: One value
double PythagThmCheck (double & len1, double & len2, double & len3);
//Function: FindHypotenuse
//Finds the hypotenuse
//Precondition: Three values, the sides
//Postcondiction: One value
double FindHypotenuse(double len1, double len2, double len3);
//Function: AnnotateResult
//The final result
//Postcondiction: One value
//Postcondiction: One value
double AnnotateResult(result);
int main()
{
double len1;
double len2;
double len3;
InputLengths(len1, len2, len3)
result = PythagThmCheck(len1, len2, len3)
AnnotateResult(result)
return 0;
}
//Function: InputLengths
//Get the three numbers
//Precondition: None
//Postcondiction: Three values, number one, number two, and number three
void InputLengths (double & len1, double & len2, double & len3);
{
//Ask the user to input userMinutes
cout << "Input number one and press enter." << endl;
cin >> len1;
cout << "Input number two and press enter." << endl;
cin >> len2;
cout << "Input number three and press enter." << endl;
cin >> len3;
}
//Function: PythagThmCheck
//Ask if the sides make up a right angle
//Precondition: Three values, the numbers
//Postcondiction: One value
double PythagThmCheck (double len1, double len2, double len3)
{
//See if the larger number is the hypotenuse
hyp = FindHypotenuse(len1, len2, len3);
switch(hyp);
case 1
ab_sides = len2 + len3;
case 2
ab_sides = len1 + len3;
case 3
ab_sides = len1 + len2;
if ab_sides = hyp
return true;
else
return false;
}
//Function: FindHypotenuse
//Finds the hypotenuse
//Precondition: Three values, the sides
//Postcondiction: One value
double FindHypotenuse(double len1, double len2, double len3)
{
if len1 > len2
greatest = 1;
size = len1;
else
greatest = 2;
size = len2;
if size > len3
return greatest;
else
return 3;
}
//Function: AnnotateResult
//The final result
//Postcondiction: One value
//Postcondiction: One value
double AnnotateResult(result)
{
if result is true
cout << "All three sides define a triangle" << endl;
else
cout << "All three sides do not define a triangle" << endl;
}