1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
void largest(int num1, int num2, int &num3);
int main()
{
int num1,num2, num3,num4, max = 0;
cout << "Enter four integers: ";
cin >> num1 >> num2 >> num3 >> num4;
cin.ignore();
largest(num1, num2, max);
largest(num2, num3, max);
largest(num3, num4, max);
cout << "The maximum number is " << max << endl;
cin.ignore();
return 0;
}
// Finds the max number of two numbers checks that number
// against max and stores the greater value in max
void largest(int num1, int num2, int &max)
{
if(num1 > num2)
{
if(num1 > max)
max = num1;
}
else if (num2 > num1)
{
if (num2 > max)
max = num2;
}
}
|