Simple Array Handling

i dont understand why my code is not compiling

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
#include <iostream>

using namespace std;

void entergrades (int &size)
{
	int temp;
	int total;
	int average;
	
	cout << "Number of grades: ";
	cin >> size;
	int grades [size];
 	
 	for (int i=1; i<size; i++)
 	{
 		cout  << "Enter grade" <<;
 		cin >> grades[i]
	 }
	 
	 
	// sorting array
	for (int = 0; i<=size; i++)
	{
		for (int j=i+1; j<=size-1; j==)
		{
			if (grades [j] < grades[i])
			{
				temp=grades[i];
				grades[i] = grades[j];
				grades[j] = temp;
			}
		}
	}
	
	// finding the sum
	for (int i=0; i < size; i++)
	{
		total += grades[i];
	}
	
	average = total/size;
	cout << average << endl;
	
	for (int i=0; i < size; i++)
	{
		cout << grades[i] << " ";
	}
	
	cout << endl;
	cout << "The average grade is: " << average << endl;
}


int main()
{
	int size;
	entergrades(size);
	
	system ("pause");
	
	return 0;
}

Last edited on
Line 13: A variable dimension is not standard C++. C++ standard requires than array dimensions be known at compile time. Some compiles do allow this as a non-standard extension.

Line 17: Extraneous <<

Line 18: Missing ;

Line 23: No variable name.

Line 25: Should be j++, not j==

Line 39: What is the value of temp the first time you execute this statement? Hint: It is garbage. temp is an uninitialized variable.

When posting about compiler errors, please post the exact text of the compiler errors.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Last edited on
Topic archived. No new replies allowed.