Expected unqualified-id and obsolete binding errors

Hi I have to write program that accepts 10 integers from the user. The program has to list the numbers the user entered, list them in reverse order, display the highest/lowest/average numbers, and output the number of integers that are above average.

I have debugged most of the problems but there are a few errors I am having trouble figuring out. I keep getting:

Line 34: error: expected unqualified-id before '=' token
Line 34: error: name lookup of `i' changed for new ISO `for' scoping
Line 25: error: using obsolete binding at `i'

I already went through the program and checked to make sure that there weren't any errors related to {}. If someone could tell me what I am doing wrong, I would really appreciate it.

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
#include <iostream>
using namespace std;

//=============================================================================
// Function prototypes
void printResults();


//=============================================================================
// Main function executes all other functions
int main()
{
  int grade[10];
  int sum;

  // For loop asks user to enter the grades one at a time
  for (int i=0; i<10; i++)
    {
      cout << "Enter a grade (no decimals, whole numbers only): ";
      cin >> grade[i];
    }

  // For loop finds the highest grade in the array
  int high = grade[0];
  for (int i=1; i<10; i++)
    {
      if (grade[i] > high)
	high=grade[i];
    }
  cout << "The highest grade is " << high << endl;

  // For loop find the lowest grade in the array
  int low = grade[0];
  for (int=10; i>10; i--)
    {
      if (grade[i] < low)
	low=grade[i];
    }
  cout << "The lowest grade is " << low << endl;

  // For loop finds the average grade in the array
  for (int i=0; i<10; i++)
    {
      sum+=grade[i];
    }
  int average;
  average = sum/10;
  cout << "The average grade is " << average << endl;

  // For loop finds the number of grades above average
  int counter =0;
  for (int i=0; i<10; i++)
    {
      if (grade[i]>average)
	counter ++;
    }
  cout << "There are " << counter << " grades above average." << endl;
}

// Displays output of information
// void printResults(); 
for (int=10; i>10; i--)

Here you are attempting to set to ten the value of a variable named int. Is there a variable named int?
That line is from the for loop I made to try and locate the lowest number. I basically took the previous for loop (to locate the highest number) and did the opposite. The declared variable for that line is int low
Assuming I made a mistake there, what is the right way to construct a for loop that finds the lowest number?
Line 34: Several problems.
- What Moschops was trying to tell you is that you didn't name a variable (i) to initialize.
- Why are you using a descending loop here?
- The first iteration of the loop is going to cause an out of bounds reference. i.e. grade[10] is not valid.
- i is never going to be greater than 10.
Use a conventional for loop here.
 
  for (int i=1; i<10; i++)


Line 14: sum is an uninitialized variable (garbage).

Line 44: You're adding grades to garbage.

Last edited on
Oh ok, that makes sense to me now. I entered your suggestion and the loop runs perfectly. Thanks for your help.
Topic archived. No new replies allowed.