1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
double larger (double x, double y);
int main ()
{
string user_Initials;
double n1, n1_b,
n2, n2_b, n3, n3_b, max;
double side_A,
side_B,
side_C_Hypotenuse;
cout << "Enter user initials: " << endl;
getline (cin,user_Initials);
cout << "Hello, this program determins type of triangle" << endl;
cout << "by evaluating the length of three sides." << endl;
cout << "Enter first number (positive numbers only)..." << endl;
cin >> n1;
max = n1;
if (n1 <= 0)
{
cout << "Invalid Entry! Input must be a number greater than zero" << endl;
cout << "Re-enter first number..." << endl;
cin >> n1_b;
cout << "Thank you!";
n1 = n1_b;
max = n1;
}
else
{
cout << n1 << " is within range..." << endl;
cout << "Thank you!" << endl;
}
cout << " Enter second number..." << endl;
cin >> n2;
max = larger(max, n2);
if (n2 <= 0)
{
cout << "Invalid entry! Enter a number GREATER than zero." << endl;
cout << "Re-enter second number..." << endl;
cin >> n2_b;
cout << "Thank you!";
n2 = n2_b;
max = larger(max, n2);
}
else
{
cout << n2 << " is within range." << endl;
cout << "Thank you!" << endl;
}
cout << " Enter third number..." << endl;
cin >> n3;
max = larger(max, n3);
if (n3 <= 0)
{
cout << "Invalid entry! Enter a number GREATER than zero." << endl;
cout << "Re-enter third number..." << endl;
cin >> n3_b;
cout << "Thank you!" << endl << endl;
n3 = n3_b;
max = larger(max, n3);
}
else
{
cout << n3 << " is within range." << endl;
cout << "Thank you!" << endl;
cout << endl;
return 0;
}
n3 larger (n1, n2)
{
if (x >= y)
return x;
else
return y;
}
side_C_Hypotenuse = max;
side_A = n1;
side_B = n2;
cout << fixed << showpoint << setprecision(2);
cout << side_A << endl;
cout << side_B << endl;
cout << side_C_Hypotenuse << endl;
return 0;
}
|