help with arrays and loops

Trying to create a program that has arrays to take grade entered and spit it back in the same order with a mark of A, B P U if below 50%, then calcs the average, the highest, and lowest grade
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
#include <iostream>

using namespace std;


void printElements(int*, int);
void enterElements(int*, int);
double calc_average(int arr[], int n);

int main()
{
	int n = 0;
	int arr[10];
	enterElements(arr, n);
	calc_average(arr, n);
	

	return 0;
}
void enterElements(int arr[], int n)
{
	do (arr[n] != 0)
	{
		for (int i = 0; i < n; i++){
			cout << "Enter Result " << i + 1 << " (or -1 if no more result): ";
			cin >> arr[n];
			// cout << endl;

			if (arr[n] == -1)
			{
				break;
			}
			if (arr[n] > 100)
			{
				i--;
				cout << "Invalid Input!" << endl;
			}
		}
	}
	printElements(arr, n);

}
double calc_average(int arr[], int n){
	double avg;
	int sum;
	int i;

	sum = 0;

	for (i = 0; i < n; i++)
	{
		sum += arr[n];
	}

	avg = sum / (double)n;
	cout << "The average of the results = " << avg << endl;
	return avg;
}

void printElements(int arr[], int n)
{
	int i = 0;
	cout << "\nSummary of the results: \n";
	for (i = 0; i < n; i++)
	{
		cout << "Result " << i + 1 << " is ";
		cout << arr[i];
		cout << endl;
	}

}
Topic archived. No new replies allowed.