#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

//------------------------prototypes----------------------------------
void ReadData(int &x, int &y, int &z);
float FindMaxMin(int x, int y, int z, float &max, float &min);
float ComputeAve(float x, float y, float z);
void ShowAll(float x, float y, float z, float average, float max, float min);
//--------------------------------------------------------------------

int main()
{
	//read data into x, y, and z
	int x, y, z;
	ReadData(x, y, z);
	
	//compute the average of x, y, z
	float average = ComputeAve(x, y, z);
	
	//find the maximum and the minimum of x, y, and z
	float max, min;
	FindMaxMin(x, y, z, max, min);

	//show all results
	ShowAll(x, y, z, average, max, min);
	
	//terminate the program
	return 0;
}

//---------------------------
// Name:    ReadData
// Input:   x, y, and z
// Output:  None
//---------------------------
void ReadData(int &x, int &y, int &z)
{
	cout << "Enter three integer numbers: ";
	cin >> x >> y >> z;
}

//-------------------------------------
//  Name:  FindMaxMin
//  Input: None
//  Output: Max and min of x, y, and z
//-------------------------------------
float FindMaxMin(int x, int y, int z, float &max, float &min)
{
	//FindMax
    if (x > y && x > z)
    {return x;}

	if (y > x && y > z)
	{return y;}
	
	else
	{return z;}


	//FindMin
    if (x < y && x < z)
    {return x;}
	
	if (y < x && y < z)
	{return y;}
	
	else
	{return z;}

}


//-----------------------------------------
// Name:    ComputeAve
// Input:   None
// Output:  Compute average of x, y, and z
//-----------------------------------------
float ComputeAve(float x, float y, float z)
{
	return (x+y+z)/3;
}

//--------------------------
//  Name: ShowAll
//  Input: None
//  Output: Everything
//--------------------------
void ShowAll(float x, float y, float z, float average, float min, float max)
{
	cout << setfill('.');
	cout << "For three numbers: " << x << " " << y << " " << z << endl;
	cout << fixed << showpoint << setprecision(2);
	cout << "\tAverage" << right << setw(30) << "" << average << endl;
	cout << "\tMinimum" << right << setw(30) << "" << min << endl;
	cout << "\tMaximum" << right << setw(30) << "" << max << endl;
}

can someone tell me why it won't read maximum and minimum?

float FindMaxMin(int x, int y, int z, float &max, float &min)
{
	//FindMax
    if (x > y && x > z)
    {return x;}
 
	if (y > x && y > z)
	{return y;}
 
	else
	{return z;}
 
 
	//FindMin
    if (x < y && x < z)
    {return x;}
 
	if (y < x && y < z)
	{return y;}
 
	else
	{return z;}
 
}

Its code like this make me wanna pull my hair.

nevermind i changed it to this and it workd

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

//------------------------prototypes----------------------------------
void ReadData(int &x, int &y, int &z);
void FindMaxMin(int x, int y, int z, int &max, int &min);
float ComputeAve(float x, float y, float z);
void ShowAll(int x, int y, int z, float average, int max, int min);
//--------------------------------------------------------------------

int main()
{
	//read data into x, y, and z
	int x, y, z;
	ReadData(x, y, z);
	
	//compute the average of x, y, z
	float average = ComputeAve(x, y, z);
	
	//find the maximum and the minimum of x, y, and z
	int max, min;
	FindMaxMin(x, y, z, max, min);

	//show all results
	ShowAll(x, y, z, average, max, min);
	
	//terminate the program
	return 0;
}

//---------------------------
// Name:    ReadData
// Input:   x, y, and z
// Output:  None
//---------------------------
void ReadData(int &x, int &y, int &z)
{
	cout << "Enter three integer numbers: ";
	cin >> x >> y >> z;
}

//-------------------------------------
//  Name:  FindMaxMin
//  Input: None
//  Output: Max and min of x, y, and z
//-------------------------------------
void FindMaxMin(int x, int y, int z, int &max, int &min)
{
	//FindMax
    if (x > y && x > z)
    {max = x;}

	if (y > x && y > z)
	{max = y;}
	
	else
	{max = z;}


	//FindMin
    if (x < y && x < z)
    {min = x;}
	
	if (y < x && y < z)
	{min = y;}
	
	else
	{min = z;}

}


//-----------------------------------------
// Name:    ComputeAve
// Input:   None
// Output:  Compute average of x, y, and z
//-----------------------------------------
float ComputeAve(float x, float y, float z)
{
	return (x+y+z)/3;
}

//--------------------------
//  Name: ShowAll
//  Input: None
//  Output: Everything
//--------------------------
void ShowAll(int x, int y, int z, float average, int min, int max)
{
	cout << setfill('.');
	cout << "For three numbers: " << x << " " << y << " " << z << endl;
	cout << fixed << showpoint << setprecision(2);
	cout << "\tAverage" << right << setw(30) << "" << average << endl;
	cout << "\tMinimum" << right << setw(30) << "" << min << endl;
	cout << "\tMaximum" << right << setw(30) << "" << max << endl;
}
void FindMaxMin(int x, int y, int z, int &max, int &min)
{
	//FindMax
    if (x > y && x > z)
    {max = x;}
 
	if (y > x && y > z)
	{max = y;}
 
	else
	{max = z;}
 
 
	//FindMin
    if (x < y && x < z)
    {min = x;}
 
	if (y < x && y < z)
	{min = y;}
 
	else
	{min = z;}
 
}

still wrong.

There's a mismatch on your signatures

ShowAll(x, y, z, average, max, min);
vs.
void ShowAll(int x, int y, int z, float average, int min, int max)

Edited 6 Years Ago by jonsca: n/a

This question has already been answered. Start a new discussion instead.