Array/Function cout issue

Hello there. My issue seems to be that my cout command is displaying all the work instead of just the final answer. At the end of the Code the cout (the last four lines) is correct so I know the calculation part is right however I can't figure out why it's spitting out what it does. Any guidance would be great.
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
89
90
91
92
93
94
95
96
97
98
Description: Program reads numbers from a txt file and displays the lowest number in the array, the highest number in the array,
total sum number of all the numbers in the array and avg number of all the numbers in the array.
Limitations or issues: 
Credits: Not Applicable
*/
#include <iostream>
#include <cmath>
#include <fstream>
using namespace std;

// Function prototypes
int getLowest(int [], int);
int getHighest(int [], int);
int getSum(int [], int);
double getAverage(int [], int);

int  main()
{
	const int ARRAY_SIZE = 12;			//array size
	int number[ARRAY_SIZE];			
	int highest, lowest, sum;		//values
	double avg;						//avg value
	int count = 0;
	
	ifstream inputFile;					//open stored file
	inputFile.open("numbers.txt");
	if (!inputFile)
	{
		cout << "Error opening File.\n";
	}
	else
	{
		for (count = 0; count < ARRAY_SIZE; count++)
		{ 
			inputFile >> number[count];
			highest = getHighest(number, ARRAY_SIZE);		//get highest number and display
			cout << "The highest value is "<< highest << endl;

			lowest = getLowest(number, ARRAY_SIZE);			//get lowest number and display
			cout << "The lowest value is " << lowest << endl;

			sum = getSum(number,ARRAY_SIZE);				//get sum and display
			cout << "The sum of the numbers is " << sum << endl;

			avg = getAverage(number,ARRAY_SIZE);			//get avg and display
			cout << "The average of the numbers is " << avg << endl;

		}//end while
		inputFile.close();
	}
	system("pause");
	return 0;
}

//Functions
int getLowest(int number[], int ARRAY_SIZE)		//get Lowest Function
{
	int lowest, count;
	lowest = number[0];
	for (count = 1; count < ARRAY_SIZE; count++)
	{
		if (number[count] < lowest)
		lowest = number[count];
	}
return lowest;
}
int getHighest(int number[], int ARRAY_SIZE)	//get Highest Function
{
	int highest, count;
	highest = number[12];
		for (count = 1; count < ARRAY_SIZE; count++)
		{
			if (number[count] > highest)
			highest = number[count];
		}
return highest;
}
int getSum(int number[], int ARRAY_SIZE)		//get Sum Function
{
	int total = 0;
		for (int count = 0; count < ARRAY_SIZE; count++)
		{
			total += number[count];
		}
return total;
}
double getAverage(int number[], int ARRAY_SIZE)		//get average Function
{
		double total = 0; // Initialize Accumulator
		double average; // To hold the average

		for (int count = 0; count < ARRAY_SIZE; count++)
		{
			total += number[count];
			average = total / ARRAY_SIZE;
		}
return average;
}
The highest value is -858993460
The lowest value is -858993460
The sum of the numbers is -858993421
The average of the numbers is -7.87411e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 128
The average of the numbers is -7.15828e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 858993653
The average of the numbers is -6.44245e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 1717987149
The average of the numbers is -5.72662e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is -1717986675
The average of the numbers is -5.01079e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is -858993190
The average of the numbers is -4.29497e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 287
The average of the numbers is -3.57914e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 858993755
The average of the numbers is -2.86331e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is 1717987277
The average of the numbers is -2.14748e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is -1717986549
The average of the numbers is -1.43166e+008
The highest value is 89
The lowest value is -858993460
The sum of the numbers is -858993002
The average of the numbers is -7.15828e+007
The highest value is 89
The lowest value is 8
The sum of the numbers is 520
The average of the numbers is 43.3333
My issue seems to be that my cout command is displaying all the work instead of just the final answer.

That's because your cout<< statements are within the loop. You should bring your cout<< statements outside the loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
for (count = 0; count < ARRAY_SIZE; count++)
{ 
     inputFile >> number[count];
     highest = getHighest(number, ARRAY_SIZE);     //get highest number and display

     lowest = getLowest(number, ARRAY_SIZE);     //get lowest number and display

     sum = getSum(number,ARRAY_SIZE);	     //get sum and display

     avg = getAverage(number,ARRAY_SIZE);     //get avg and display
}//end while

inputFile.close();

cout << "The highest value is "<< highest << endl;
cout << "The lowest value is " << lowest << endl;
cout << "The sum of the numbers is " << sum << endl;
cout << "The average of the numbers is " << avg << endl;


You should also be careful here: highest = number[12]; (12 is beyond the indexable range of the array).

Also, there is no need to calculate the lowest, highest, sum, and average every single time a new number is added. It's sufficient to do all those calculations after all the numbers have been read.
Thanks for a quick response. I really appreciate the help.
Topic archived. No new replies allowed.