// CS101 Laboratory #3: Inquiring about the IF statement // Description: This program provides some demonstrations of the // IF statement. // Program expects as input three numbers in nondecreasing order. It then // determines whether the numbers correspond to lengths of sides of a triangle #include #include using namespace std; int main() { int Side1; int Side2; int Side3; // prompt use to type 3 numbers in nondecreasing order cout << "\n\n" << "Please type in lengths of sides of your possible triangle.\n" << "We require that the numbers be in nondecreaing order.\n" << "That is, first number <= second number <= third number.\n\n"; cout << "First number: "; cin >> Side1; cout << "Second number: "; cin >> Side2; cout << "Third number: "; cin >> Side3; cout << endl; // make sure user followed our rules if ( (Side1 > Side2) || (Side2 > Side3) ) { // they did not follow the instructions cout << "Bad numbers. Program quits\n"; return 0; } // check to see whether numbers do form sides of a triangle or not if (Side1 + Side2 <= Side3) { // numbers do not form a triangle cout << "Numbers are not the sides of a triangle.\n"; } else if (Side1 == Side3) { // numbers form a equilateral triangle cout << "Numbers are the sides of an equilateral triangle.\n"; } else if ( (Side1 == Side2) || (Side2 == Side3) ) { // numbers form an isosceles triangle cout << "Numbers are the sides of an isosceles triangle.\n"; } else { // triangle is scalene cout << "Numbers are the sides of a scalene triangle.\n"; } // we are all done return 0; }