Loop Troubles

I can't figure out why, but for some reason this loop seems to only ever think q=4. It displays whatever the fourth grade entered for each person is for each of that student's grades, and I have no idea why.

1
2
3
4
5
            else if((x>0)&&(x<5)){
                for(int q=0; q<4; q++){
                    output[i][x]=grades[i][q];
                }
            }
The problem isn't directly shown here, I suggest posting relevant info such as when you fill up the grades array, the other if statements, etc.
Here are the other conditionals:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
            if((x==0)){
                output[i][x]=names[i][x];
            }
            else if((x>0)&&(x<5)){
                for(int q=0; q<4; q++){
                    output[i][x]=grades[i][q];
                }
            }
            else{
                    output[i][5]=average[i][0];
            }
            cout<<output[i][x];
            if(x>=5){
                cout<<endl;
            }
            else{
                cout<<"\t";
            }


And this is the input:
1
2
3
4
5
6
7
8
9
10
11
12
void gradeInput(int grades[][4]){
    //inputs the grades
    cout<<"Enter the grades:"<<endl;
	for(int i=0; i<3; i++){
		cout<<"Student "<<i+1<<endl;
		for(int j=0; j<4; j++){
			cout<<"     Test "<<j+1<<": ";
			cin>>grades[i][j];
		}
		cout<<endl;
	}
}
Nevermind. I've fixed it. I just needed get rid of the for loop and replace q with x-1.

1
2
3
            else if((x>0)&&(x<5)){
                output[i][x]=grades[i][x-1];
            }
Topic archived. No new replies allowed.