Random number problem; i changed for ISO

I'm trying to create a program generating a set of random numbers each time its run. The code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int main(){
   //generates a new random set each time:
   srand(time(0));

   int arr[20] = {0};

   for(int i = 0; i < 20; i++){
      //random numbers from 1 to 10:
      arr[i] = rand() % 10 + 1;
   }

   for(i = 0; i < 20; i++){
      cout << arr[i] << " ";
   }

   return 0;
}


When I run the program I get a strange error message and a wierd note:


error: name lookup of 'i' changed for ISO 'for' scoping

note: (if you use '-fpermissive' G++ will accept your code)


What am I supposed to do to solve the problem and what is '-fpermissive'?
the int i you declared in the first for loop exist only for this for loop. its not accesable from lower instances. so you need to declare it in the second loop, too.
Topic archived. No new replies allowed.