I'm creating a program that inputs three integers, and returns the sum, product, average, largest and smallest. Very simple, but I'm getting a bad return on one of my variables. Except for my "largest" variable, the others are returning the correct numbers. I'm hoping that someone can tell me where I'm going wrong.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int num1, num2, num3, sum, average, product, smallest, largest;
cout << "Input three different integers: ";
cin >> num1 >> num2 >> num3; // read three integers
sum = num1 + num2 + num3;
average = ( (num1 + num2 + num3) / 3 );
product = num1 * num2 * num3;
if ( num1 < num2 )
smallest = num1;
if ( num2 < num1 )
smallest = num2;
if ( num3 < smallest )
smallest = num3;
if ( num1 > num2 )
largest = num1;
if ( num2 > num1 )
largest = num2;
if ( num3 > largest )
largest = num3;
cout << "\nSum is " << sum;
cout << "\nAverage is " << average;
cout << "\nProduct is " << product;
cout << "\nSmallest is " << smallest;
cout << "\nLargest is " << largest << endl;
return 0; // indicates that program ended successfully
}
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int num1, num2, num3, sum, average, product, smallest, largest;
cout << "Input three different integers: ";
cin >> num1 >> num2 >> num3; // read three integers
sum = num1 + num2 + num3;
average = ( (num1 + num2 + num3) / 3 );
product = num1 * num2 * num3;
if ( num1 < num2 )
smallest = num1;
if ( num2 < num1 )
smallest = num2;
if ( num3 < smallest )
smallest = num3;
if ( num1 > num2 )
largest = num1;
if ( num2 > num1 )
largest = num2;
if ( num3 > largest )
largest = num3;
cout << "\nSum is " << sum;
cout << "\nAverage is " << average;
cout << "\nProduct is " << product;
cout << "\nSmallest is " << smallest;
cout << "\nLargest is " << largest << endl;
return 0; // indicates that program ended successfully
}