Understanding if else Statements in C ++:

#include <iostream>
using namespace std;
int main()
{
// This is the work done in the housekeeping() function
// Declare and initialize variables here
int largest; // Largest of the three values
int smallest; // Smallest of the three values

// Prompt the user to enter 3 integer values
int NUM1 = 0;
int NUM2 = 0;
int NUM3 = 0;
// This is the work done in the detailLoop() function
cout << "Enter first number: ";
cin >> NUM1;

cout << "Enter second number: ";
cin >> NUM2;

cout << "Enter third number: ";
cin >> NUM3;
// Write assignment and conditional statements here as appropriate

if( NUM1 < NUM2){
largest = NUM2;
smallest = NUM1;
}
else{
smallest = NUM2;
largest = NUM1;
}
if ( NUM2 < NUM3 ){
largest = NUM3;
smallest = NUM2;
}
else{
smallest = NUM3;
largest = NUM2;
}
if ( NUM1 < NUM3){
largest = NUM3;
smallest = NUM1;







// This is the work done in the endOfJob() function
// Output largest and smallest number.

cout << "The largest value is " << largest << endl;
cout << "The smallest value is " << smallest << endl;
return 0;

}}
Is this a question, or an example?
Topic archived. No new replies allowed.