//****************************************************************** // Triangle program // This program exercises the IsTriangle function //****************************************************************** #include #include // For fabs() using namespace std; bool IsTriangle( float, float, float ); int main() { float angleA; // Three potential angles of a triangle float angleB; float angleC; cout << "Enter 3 angles: "; cin >> angleA; while (cin) { cin >> angleB >> angleC; if (IsTriangle(angleA, angleB, angleC)) cout << "The 3 angles form a valid triangle." << endl; else cout << "Those angles do not form a triangle." << endl; cout << "Enter 3 angles: "; cin >> angleA; } return 0; } //****************************************************************** bool IsTriangle( /* in */ float angle1, // First angle /* in */ float angle2, // Second angle /* in */ float angle3 ) // Third angle // This function checks to see if its three incoming values // add up to 180 degrees, forming a valid triangle // Precondition: // angle1, angle2, and angle3 are assigned // Postcondition: // Function value == true, if (angle1 + angle2 + angle3) is // within 0.00000001 of 180.0 degrees // == false, otherwise { return (fabs(angle1 + angle2 + angle3 - 180.0) < 0.00000001); }