can anybody tell me what is wrong is my code

i am trying to get all the array arrange in 1 2 3 and - with 128
4 5 6
7 8 9

#include <iostream>
using namespace std;

int main()
{
int a;
int x;
int y;
int array[3][3];
array[0][0] = 1;
array[0][1] = 2;
array[0][2] = 3;
array[1][0] = 4;
array[1][1] = 5;
array[1][2] = 6;
array[2][0] = 7;
array[2][1] = 8;
array[2][2] = 9;

for ( x = 0; x < 3; x++ ) {
for ( y = 0; y < 3; y++ )

a = array[x][y] - 128;

cout << a << endl;
}
return 0;
}
You need some more braces:
1
2
3
4
5
6
7
8
for ( x = 0; x < 3; x++ ) {
    for ( y = 0; y < 3; y++ ) {

        a = array[x][y] - 128;

        cout << a << endl;
    }
}


Please use [code][/code] tags
You want your function to print 9 lines and not 1?
In this case you'll have to add the brackets of the second for-loop, because the second loop affects a = array[x][y] - 128; only and not cout << a << endl;

by the way, use code-tags next time please

Edit: too slow...
Last edited on
it is still the same when i added the braces it is just one line i want it to be
1 2 3
4 5 6
7 8 9

like matrix form
the output can not be the same if you added the brackets at the correct position..

well, maybe this code will work for you:

1
2
3
4
5
6
7
for ( x = 0; x < 3; x++ ) {
    for ( y = 0; y < 3; y++ ) {
        a = array[x][y] - 128;
        cout << a << ' ';
    }
cout << endl;
}
thx man it works
Topic archived. No new replies allowed.