Help with arrays Calculating average c++

I have already written most of the codes. The only thing i am missing is calculating AVERAGE and SUM of the number in .txt file.

numbers in the .txt file are :47
89
65
36
12
25
17
8
62
10
87
62

If anyone can help, it would be much appreciated.

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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// This program lets the user enter a filename.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int getLowest(const int[], int);
int getHighest(const int[], int);


int main()
{
	ifstream inputFile;
	string filename;
	int number;
	const int ARRAY_SIZE = 12; // Array size
	int numbers[ARRAY_SIZE];    // Array with 100 elements
	int count = 0;
	int lowestNumber, highestNumber , sumNumber=0; 

	// Get the filename from the user.
	cout << "Please enter the name of the file to read numbers for Number Analysis Program:\n";
	cin >> filename;

	// Open the file.
	inputFile.open(filename);

	// If the file successfully opened, process it.
	if (inputFile)
	{
		// Read the numbers from the file and
		// display them.
		while (count < ARRAY_SIZE && inputFile >> numbers[count])
			count++;

		// Close the file.
		inputFile.close();

		// Display the numbers read.
		cout << "The numbers are: ";
		for (int index = 0; index < count; index++)
			cout << numbers[index] << " ";
		cout << endl;


	}
	else
	{
		// Display an error message.
		cout << "Error opening the file.\n";
	}

	for (int i = 0; 1 < ARRAY_SIZE; i++)
	{
		sumNumber += numbers[i];
}
	cout << "The sum of the numbers are: " << sumNumber << endl;
	// Get the lowest test score.
	highestNumber = getHighest(numbers, ARRAY_SIZE);

	lowestNumber = getLowest(numbers, ARRAY_SIZE);




	

	system("pause");
	return 0;
}

int getLowest(const int array[], int size)
{
	int lowest;  // To hold the lowest value

					// Get the first array's first element.
	lowest = array[0];

	// Step through the rest of the array. When a
	// value less than lowest is found, assign it
	// to lowest.
	for (int count = 1; count < size; count++)
	{
		if (array[count] < lowest)
			lowest = array[count];
	}

	cout << "The lowest nuber is " << lowest << endl;

	// Return the lowest value.
	return lowest;
}

int getHighest(const int array[], int size)
{
	int highest;  // To hold the lowest value

					// Get the first array's first element.
	highest = array[0];

	// Step through the rest of the array. When a
	// value less than lowest is found, assign it
	// to lowest.
	for (int count = 1; count < size; count++)
	{
		if (array[count] > highest)
			highest = array[count];
	}

	cout << "The highest nuber is " << highest << endl;

	// Return the lowest value.
	return highest;
}
After the loop on line 33 you should use count not ARRAY_SIZE.

The only thing i am missing is calculating AVERAGE and SUM of the number in .txt file.
Um? sumNumber already contains the sum. You need to divide it by count and you will have the average.

By the way: See line 16. The size of the array is not 100.
Topic archived. No new replies allowed.