problem with array when trying to compile

I have been sitting at this for 2 hours now, and can't figure out what the heck the problem is. I believe the program is pretty much finished - the problem is something with the array. I am trying to pass by reference to a function, and then.... well.. maybe you can help? The program is supposed to read from a file minmax.in into an array ... the numbers go one after the other on a single line in a seperate 'txt file'. I have not programmed in 10 years... and now i'm just jumping back into the 'game'.


void readdat(float& x, int& n);
void minmax(float x, int& n, float& max, float& min);

#include <iostream>
#include <fstream>

using namespace std;

const int N = 100; // maximum array size

int main(void)
{
ofstream outfile("minmax.out");

float x[N]; // the array
int n; // the actual array size
float max; // the maximum
float min; // the minimum

/* read the data into the array */
readdat(x[N],n);

/* compute the maximum and minimum */
minmax(x[N],n,max,min);

outfile << "The array has " << n << " elements\n";
outfile << "The maximum value in the array is " << max << endl;
outfile << "The minimum value in the array is " << min << endl;
return 0;
}

void readdat(float& x,int& n )
{ n=0;
int i=0;
float temp=0;
ifstream fin("minmax.in");
while (!fin.eof())
{
fin>>temp;
x[i]=temp;
i++;
}
n=i;


}
void minmax(float x[],int& n, float& max, float& min )
{ int count=0;
max=x[count];
min=x[count];
count++;
while (count!=n)
{if (x[count]>=max) max=x[count];
if (x[count]<=min) min=x[count];
count++;
}

}
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
void readdat(float& x, int& n);
void minmax(float x, int& n, float& max, float& min);

#include <iostream>
#include <fstream>

using namespace std;

const int N = 100; // maximum array size

int main(void)
{
ofstream outfile("minmax.out");

float x[N]; // the array 
int n; // the actual array size 
float max; // the maximum 
float min; // the minimum 

/* read the data into the array */
readdat(x[N],n);

/* compute the maximum and minimum */
minmax(x[N],n,max,min); 

outfile << "The array has " << n << " elements\n";
outfile << "The maximum value in the array is " << max << endl;
outfile << "The minimum value in the array is " << min << endl;
return 0;
}

void readdat(float& x,int& n )
{ n=0;
int i=0;
float temp=0;
ifstream fin("minmax.in");
while (!fin.eof())
{
fin>>temp;
x[i]=temp;
i++;
}
n=i;


} 
void minmax(float x[],int& n, float& max, float& min )
{ int count=0;
max=x[count];
min=x[count];
count++;
while (count!=n)
{if (x[count]>=max) max=x[count];
if (x[count]<=min) min=x[count];
count++;
}

} 
Topic archived. No new replies allowed.