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 39 40 41 42 43 44
|
#include<iostream>
#include <iomanip>
using namespace std;
void ReadData(int & x, int & y, int & z)
{
cout << "Enter three integer numbers: ";
cin >> x >> y >> z;
}
//Comput total of x, y, z
int ComputSum(int a, int b, int c){ return a + b + c; }
//Compute average of x, y, z
float ComputAverage(int a, int b, int c){ return (a + b + c )/3.0f; }
//Display total and average
void Display(int total, float average)
{
cout << fixed << showpoint << setprecision(2);
cout << "Total= " << total << endl;
cout << "Average= " << average << endl;
}
void findMinMax( int x, int y, int z, int& min, int& max )
{
min = max = x;
if( y < min ) min = y;
if( z < min ) min = z;
if( y > max ) max = y;
if( z > max ) max = z;
}
int main()
{
int x, y, z;
ReadData( x, y, z);
Display( ComputSum( x, y, z ), ComputAverage( x, y, z ) );
int min, max;
findMinMax( x, y, z, min, max );
cout << "the max and min values of " << x << ", " << y << "," << " and " << z
<< " are " << max << " and " << min << endl;
//Terminate the program
system("pause");
return 0;
}
|