If you try typing text, you'll see that it goes from left to right. If you press enter, you go one line down, and start typing again, from left to right.
Try to execute your code by yourself. Simply do what it says. You will find the mistake quickly:)
Actually your loop doesn't work really well. 30 times your program will do following instructions:
- set board[0][0-19] to '*'(for example, it's gonna set board[0][0] to '*' 30 times)
- set board [30][0-19] to '*' 30 times
- set board [0-29][20] to '*' 30 times
What you actually wanna do is:
- Set top row to '*'(once :) )
- Set most left column and most right column to '*'
- Set bottom row to '*'
To accomplish this, using for loop, I'd do something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
for(int i = 0; i < 30; i++)
{
for(int j = 0; j < 20; j++)
{
if(i == 0 || i == 29 || j == 0 || j == 19)
//if we are filling first or last row, or first or last column, put there '*'
board[i][j] = '*';
else
board[i][j] = ' ';
}
}
for(int i = 0; i < 30; i++)
{
for(int j = 0; j < 20; j++)
cout<<board[i][j];
cout<<endl;
|
I believe it's what you aimed at. If you want to do it other way, like you want to have multiple rows, you have to change code.
Hope it helps.