Averaging Problems

i feel stupid asking this because ive made programs that average numbers before, but right now im baffled. the problem i have to solve is as follows:

write a native c++ program that allows an unlimited number of values to be entered and stored in an array allocated in the free store. the program should then output the values five to a line followed by the average of the values entered. the initial array size should be five elements. the program should create a new array with five additional elements when necessary and copy values from the old array to the new.

here is my code:
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
#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
using std::setw;

int main()
{
	int* numbers = new int[];
	int numberCounter = 0;
	int current[5] = { 0 };
	char indicator = 'y';

	while (indicator == 'y' || indicator == 'Y')
	{
		cout << "Enter five new numbers: " << endl;
		for (int i = 0; i < 5; i++)
		{
			cin >> current[i];
			numbers[numberCounter] =  current[i];
			numberCounter++;
		}
		cout << "Continue (Y/N)? ";
		cin >> indicator;
	}

	cout << endl << endl;
	
	int average = 0;
	for (int i = 0; numberCounter > 0; numberCounter--, i++)
	{
		average += numbers[i];
		if (i % 5 == 0)
		{
			cout << endl;
			cout << setw(9) << "Average: " << average / 5;
			average = 0;
		}
		cout << "   " << setw(10) << numbers[i];
	}
	
	cout << endl;
	return 0;
}


everything is working EXCEPT for the average part, which is giving retarded answers that just dont make sense. please help me out here :-)
Last edited on
I'm not sure what you are trying to do on the average calculation; are you trying to print the average of each set of five numbers? I do not think that's what you are supposed to do - the assignment says print them "five to a line" and then the average...of all of the numbers.
i was going for the average of each set of 5, but i think youre right! ill just do it that way, thanks!
Last edited on
Topic archived. No new replies allowed.