undeclared indentifier

I keep getting undeclared identifier j , why? I do declare it in the for loop though.

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

#include<iostream>
#include<iomanip>

int main()
{
const int arraySize = 10; // sets the array size
int myArray[arraySize] = {37, 89, 12, 8, 10, 4, 6, 68, 45, 2};
int hold; // the location to swap array elements

std::cout<<"Data items in original order\n";

for( int i = 0; i < arraySize; i++)
std::cout<<std::setw(4)<<myArray[i];
   


    //loop to control number of passes
for( int i = 1;  i < arraySize -1  ; i++)
{
    
        for ( int j = 0;j< arraySize -1  ; j++ );
        {
           if( myArray [ j ] > myArray [ j+1 ] ) //compare and swap the elements
           {
            
          hold = myArray[ j ]; 
          myArray[ j ]=myArray[ j+1];
          myArray[ j+1] = hold ;
          
           }
        }
}
            
 
       

     std::cout<<" Data items in ascending order\n";

     for(int k = 0 ; k < arraySize ; k++ )
     
         std::cout<<std::setw(4)<< myArray[k]
         <<std::endl;
     






}// end main 
for ( int j = 0;j< arraySize -1 ; j++ );

There is semicolon on the end of this loop that is a mistake.
On line 22 you have a stray semicolon after the for loop. Which makes the for loop empty.

As a result... the block starting on line 23 is not part of the for loop and therefore does not have j defined.
hey yes I just realized that , I can't believe i missed it so many times . How can u spot it so fast !
thanks a lot.
Topic archived. No new replies allowed.