Private, public

Need help to fix errors:

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
using namespace std;

class TWO
{
private: int age[5];
public:
//read data into array
void ReadData(int age[], int n);
//member to return the average of data in array age of object p
friend  int FindAverage(TWO p);
//member to find and return the max and min age
void FindMaxMin(int &maxAge, int& minAge, int age[], int n);
//display ages > age average
void DisplayAboveAverage(int ageAve, int age[], int n);
//display the max and min ages
void DisplayMaxMinAge(int maxAge, int minAge, int age[], int n);
//release all memory used by objects
~TWO() {}
};

int main()
{
int a[]; int n;
int maxAge;
int minAge;
int ageAve;
TWO x;

x.ReadData(a[],n);
FindAverage(x);
x.FindMaxMin(maxAge,minAge);
x.DisplayAboveAverage(ageAve);
x.DisplayMaxMinAge(maxAge, minAge);

return 0;
}

// class functions
void TWO :: ReadData(int x[], int n)
{
for(int i = 0; i < 5; ++i)
	{	cout << "Enter 5 ages: "; 
		cin >> x[i];
	}
}
void FindAverage(TWO p, int x[], int n)
{	int total = 0;
	for(int i = 0; i < 5; ++i)
	{	
		total += x[i];
	}

}
void TWO :: FindMaxMin(int &maxAge, int& minAge, int x[], int n)
{
	
	int maxAge = x[0];
	for(int i = 0; i < 5; ++i)
	if(maxAge < x[i])
		maxAge = x[1];
	int minAge = x[0];
	for(int i = 0; i < 5; ++i)
	if(minAge > x[i])
		minAge =  x[3];
}
void TWO :: DisplayAboveAverage(int ageAve, int x[], int n)
{
	int total = 0;
	for(int i = 0; i < 5; ++i)
	{	
		total += x[i];
		if(ageAve > total)
			cout << 
	}

}
void TWO :: DisplayMaxMinAge(int maxAge, int minAge, int x[], int n)
{
	int maxAge = x[0];
	for(int i = 0; i < 5; ++i)
	if(maxAge < x[i])
		cout << "Maximum age is " << x[1];
	int minAge = x[0];
	for(int i = 0; i < 5; ++i)
	if(minAge > x[i])
		cout <<  x[3];
}


Output should look like this:
1
2
3
4
Enter 5 ages: 22 27 19 17 25
  Ages above average: 27 25
  Maximum age is 25
  Minimum age is 17
Last edited on
error line 74.

1
2
3
4
5
6
7
8
9
10
11
void TWO :: DisplayMaxMinAge(int maxAge, int minAge, int x[], int n)
{
	int maxAge = x[0]; // redefinition
	for(int i = 0; i < 5; ++i)
	if(maxAge < x[i])
		cout << "Maximum age is " << x[1];
	int minAge = x[0]; // redefinition
	for(int i = 0; i < 5; ++i)
	if(minAge > x[i])
		cout <<  x[3];
}



line 24: int a[]; the size of an static array should be specified at the moment you declare it.

line 30,32,33,34: the function calls doesnt match with the function prototypes.
Declaration of unused variables/arrays
e.g int a[]; int n;

two few arguments for call to functions in 'class TWO'

the size of the array int X[] is unknown;

This should work fine
http://cpp.sh/32m3q
yea fixed some stuff but still not really working right.
The one @N495t4r showed that you said worked didn't work for me, gave me a ton of errors.
@N495t4r's code works Fine.

But you probably dont want to use global variables.
Last edited on
Oh, cause when I tried it on that site it worked fine and got this output:
1
2
3
4
5
6
Enter 5 ages: 22 27 19 17 25
Enter 5 ages: Enter 5 ages: Enter 5 ages: Enter 5 ages: 
AVERAGE: 22
Maximum age is 27
Minimum age is 17
Ages above Average: 27 25  


but when I tried on Visual Studio 2013 it had some errors like uninitialized or something like that. How do I make the "Enter 5 ages" part not come up 5 times though?
thanks
Just try setting ageAve to = 0 in the beginning.

The reason its asking 5 time is becuase of your loop

1
2
3
4
for(int i = 0; i < 5; ++i)
	{	cout << "Enter 5 ages: "; 
		cin >> x[i];
	}


You see here how this runs 5 times?

Isint that what you want though?
Topic archived. No new replies allowed.