I know this is kinda out there, but if any of you know C++ maybe you can help me.
I am taking a class on C++ and I've been working on a simple program. You input 3 different intergers, and the program has to calculate and display the sum, product, average. That's the really easy part.
The last part is that you have to have the program display shich interger is the largest, and which is the smallest.
This is how I coded this program.
// Problem 1.26
#include <iostream>
#include <cmath>
using namespace std;
void main()
{
int x1, x2, x3, sum, ave, pro;
cout << "Input three different integers:\n";
cin >> x1 >> x2 >> x3;
sum = x1 + x2 + x3;
cout << "Sum is " << sum << endl;
ave = sum / 3;
cout << "Average is " << ave << endl;
pro = x1 * x2 * x3;
cout << "Product is " << pro << endl;
if ( x1 > x2 && x1 > x3 )
cout << x1 << " is the largest.\n";
if ( x2 > x1 && x2 > x3 )
cout << x2 << " is the largest.\n";
if ( x3 > x1 && x3 > x2 )
cout << x3 << " is the largest.\n";
if ( x1 < x2 && x1 < x3 )
cout << x1 << " is the smallest.\n";
if ( x2 < x1 && x2 < x3 )
cout << x2 << " is the smallest.\n";
if ( x3 < x1 && x3 < x2 )
cout << x3 << " is the smallest.\n";
}
My question is, is there an easier way to have it determine and display which integer is largest/smallest?
