#include <iostream>
#include <cmath>
usingnamespace std;
int maximum;
void set_max(int a)
/* PURPOSE: Updates maximum if parameter is larger
RECEIVES: a - the value to compare against maximum
REMARKS: Uses global int maximum
*/
{ if (maximum < a)
{ maximum = a;
}
}
void max3(int &i, int& j, int& k)
{ maximum = i;
set_max(j);
set_max(k);
return maximum;
}
int main()
{ cout << "Please enter the first integer: ";
cin >> i;
cout << "Please enter the second integer: ";
cin >> j;
cout << "Please enter the third integer: ";
cin >> k;
maximum = max3(i, j, k);
cout << "The maximum is " << maximum << "\n"return 0;
}
First of all I do not see where i, j, and k are declared in your program
As for the program then it can be written simpler without using any global variable.
#include <iostream>
usingnamespace std;
int max3( int i, int j, int k )
{
int max = i;
if ( max < j ) max = j;
if ( max < k ) max = k;
return ( max );
}
int main()
{
int i, j, k;
cout << "Please enter the first integer: ";
cin >> i;
cout << "Please enter the second integer: ";
cin >> j;
cout << "Please enter the third integer: ";
cin >> k;
cout << "The maximum is " << max3( i, j, k ) << "\n"return 0;
}