Wel nice try, was a good logic, try to reduce the unnecessary passing of addresses( wel that doesnt affect the output)
Here i have made small corrections. it works fine
CODE
#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int a[5];
// Prototype Declarations
void openFile(ifstream& inFile, string name);
int readValues (ifstream& infile, int numbers[]);
void printValues(int y, int k, const int numbers[], int number_elements);
void rowMinMax(int x,int x[], int numberValues, int& max, int& min);
void minMax(int numbers[], int numberValues, int& max, int& min);
int main (void)
{
// Local Declarations
int number_elements; // number of elements actually stored in numbers[] array
int i;
int numberValues;
int numbers[100]; // numbers read from the data file
ifstream infile; // inputfile stream
int min, max;
string filename;
int x,y,k,z;
x=y=k=z=number_elements=numberValues=min=max=i=0;
// Statements
cout << "This program will read numbers from a file, store them in an array" << endl;
cout << "and print the numbers." << endl;
cout << "Enter the file to be processed:" << endl;
cin >> filename; //reading in the filename
cout << endl << endl;
openFile(infile, filename); //opening the file specified by the user
infile >> x >> y;
cout << " " << x << " " << y;
k = x*y;
// read the data and store it in the array
numberValues=readValues (infile, numbers);
// print the data in the array
printValues (y, k, numbers, number_elements);
rowMinMax(x,numbers, y, max, min);
//cout << "min: " << min << "max: " << max;
// find the minimum and maximum value in the array
minMax(numbers, k, max, min);
cout << "The minimum value is " << min << " and the maximum value is " << max << endl;
system("pause");
return 0;
} // main
/* ================== openFile ==================
Open a text file and return the file stream.
*/
void openFile(ifstream& inFile, string name) //opens the file unless there's an error which causes the program to exit
{
inFile.open(name.c_str());
if (inFile == false)
{
cout << "There was an error opening the file" << endl;
system("pause");
exit(0);
}
}
/* ================== readValues ==================
Read up to 100 integers from file specified by infile into array.
Returns the number of values read from file
*/
int readValues(ifstream& infile, int numbers[])
{
int numbervalues = 0;
int i = 0;
while (i < 100 && infile)
{
infile >> numbers[i];
i++;
}
numbervalues = i;
return numbervalues;
}
/* ================== printData ==================
Prints the data on multiple lines if needed
Pre data: a filled array
number_elements: size of array to be printed
Post The data have been printed
*/
void printValues (int y, int k, const int numbers[], int number_elements)
{
// Local Declarations
int i, j;
int numPrinted = 0;
int lineSize = y; // number of values to print on each line
number_elements = k;
// Statements
cout << endl << endl;
for (i = 0; i < number_elements; i++)
{
numPrinted++;
cout << setw(4) << numbers[i];
if (numPrinted >= lineSize)
{
cout << endl;
numPrinted = 0;
} // if
} // for
cout << endl << endl;
return;
}
void rowMinMax(int z,int x[], int numberValues, int& max, int& min)
{
max = 0;
min = 99999;
int i,d,c;
c=0;
for (d = 0; d < z; d++)
{
for (i=numberValues*c; i<numberValues*(c+1); i++)
{
if (x[i] > max)
max = x[i];
if (x[i] < min)
min = x[i];
}
cout << "min: " << min << "max: " << max<<endl;
c++;
max=-1;
min=99999;
}
}
/* ================== minMax ==================
Return the minimum and maximum number in the array.
*/
void minMax(int numbers[], int numberValues, int& max, int& min)
{
max = 0;
min = 99999;
int i;
for (i=0; i<numberValues; i++)
{
if (numbers[i] > max)
max = numbers[i];
if (numbers[i] < min)
min = numbers[i];
}
}