It is supposed to read the first line of a 2d array([4][4]) and display its first elementh. The compilation is ok so i think there is a logical problem. after i enter the input it stucks anything i do it just goes on without displaying output or closing. Do you think you can help?
Thanks in advance!
When you declare the char field[4][4] you are declaring a 4x4 array. Since arrays count from 0 and not 1, that means the highest index will be 3, but your while loop will be true when i=4.
on line 10 change it to a < operator instead of <=. Also you are only looping for the second column not the first for that you need to do a loop inside of a loop.
also since you have a known game size you should make that a constant value and use a for loop since the amount of times to loop is known.
1 2 3 4 5 6 7 8 9 10
constint WIDTH = 4 , HEIGHT = 4;
char field[WIDTH][HEIGHT];
for( int i = 0; i < WIDTH; ++i )
{
for( int j = 0; j < HEIGHT; ++j )
{
cin >> field[i][j];
}
}
Hope this helps let me know if you don't understand.