Max and min come out wrong, they go to 0's when it outputs ? How do I fix, any solutions??

``````#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
int x, y, z;
int total;
float average;

//Read data into x, y, z
void ReadData(int & x, int & y, int & z); {
{
cout << "Enter three integer numbers: ";
cin >> x >> y >> z;
}

//Comput total of x, y, z
int total;
int ComputSum(int a, int b, int c);

//Compute average of x, y, z
void ComputeAverage(int x, int y, int z);
{  float average = (x + y + z);
//Display total and average
void Display(int total, float average);
{
cout << fixed << showpoint << setprecision(2);
cout << "Total= " << x + y + z << endl;
cout << "Average= " << average / 3 << endl;
}
}
void FindMaxMin(int x, int y, int z, int max, int min);
int max=0,num=0,min=1000;
for (int i=0; num!=1; i++)
{
if(num==-1)break;
if (num>max)
max=num;
if (num<min)
min=num;
cout << "the max and min values of " << x << "," << y << "," << " and " << z
<< " are " << max << " and " << min;
cin.ignore(80, 'n');
}

//Terminate the program
system("pause");
return 0;
}
}
``````

The for loop inyour FindMaxMin function makes no sense at all, and you never call it, and it seems to be buried inside your main function, and you've go ta semi-colon at the end of line 34 so you don't actually even have a findMinMax function - you've just got …

## All 2 Replies

The for loop inyour FindMaxMin function makes no sense at all, and you never call it, and it seems to be buried inside your main function, and you've go ta semi-colon at the end of line 34 so you don't actually even have a findMinMax function - you've just got a declaration of it. Which is the same for many other functions. A big mess.

Is this the first time you've tried to write a function? You've got it completely wrong. You need to go back to whatever you're trying to learn how to write a function from and start again.

First thing i see, there are functions within functions. That is not right, is it? Or is it something new that has come along with C++0x?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.