I did that[You should just remove line 11 and replace it with line 15.], now whenever it reads my input it exits the program instantly. |
It shouldn't unless you are entering the data in the incorrect order.
Basically if I under stand this correctly if the example with a width of 2 it would look like:
aa bb cc dd aa bb
aa bb cc dd aa bb
bb cc dd aa bb cc
bb cc dd aa bb cc
cc dd aa bb cc dd
cc dd aa bb cc dd
dd aa bb cc dd aa
dd aa bb cc dd aa
aa bb cc dd aa bb
aa bb cc dd aa bb |
So lets think about this:
For a grid L x H we would need 2 loops one for rows and one for columns
1 2
|
for( int row = 0; row < ROWS; ++row )
for( int column = 0; column < COLUMNS; ++column )
|
This will go through each tile and each tile is W x W in dimensions so we would need another 2d loop as earlier both will be for the width.
Basically we have the rows for the grid , rows of the element , columns of grid , and columns of element
So it should look like:
1 2 3 4
|
for( int row = 0; row < ROWS; ++row )
for( int i = 0; i < WIDTH; ++i )
for( int column = 0; column < COLUMNS; ++ column )
for( int j = 0; j < WIDTH; ++j )
|
So lets look at your formula:
SC + (r+c)%CS
now lets put it into use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
for( int gridrow = 0; gridrow < rows; ++gridrow )
{
for( int elementrow = 0; elementrow < width; ++elementrow )
{
for( int gridcolumn = 0; gridcolumn < columns; ++gridcolumn )
{
for( int elementcolumn = 0; elementcolumn < width; ++elementcolumn )
{
cout << static_cast<char>( character + ( gridrow + gridcolumn ) % cycle );
}
cout << ' ';
}
cout << endl;
}
}
|
aa bb cc dd aa bb
bb cc dd aa bb cc
bb cc dd aa bb cc
cc dd aa bb cc dd
cc dd aa bb cc dd
dd aa bb cc dd aa
dd aa bb cc dd aa
aa bb cc dd aa bb
aa bb cc dd aa bb |
http://ideone.com/oGmQLj
[edit] For some reason it is not displaying the first
in the output of the code I provided I think there is a bug with the "--- aa bb cc dd aa bb " not finding the first line.
Looking at your code you were very close you just had your loop in slight wrong order and you added to the SC for some reason the professor/sample output you had did not.