### HELP!!! arrays and loops

Hey guys, I need to create a table that is 14 rows by 7 columns. I need it to appear like:
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 15 0 0 0 0 15 0 0 0 0
0 15 15 15 15 15 15 15 15 15 15 15 15 0
0 0 0 0 15 0 0 0 0 15 0 0 0 0
0 15 15 15 15 15 15 15 15 15 15 15 15 0
0 0 0 0 15 0 0 0 0 15 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0

How do i get the 0 to change to 15s in the middle of the line? I have been trying for a while and i'm still stuck. Any help at all would be greatly appreciated!!!!

Heres my code so far:

 ``12345678910111213141516171819`` ``````#include using namespace std; int main () { cout << "P2 14 7 15" << endl; int array[98] = {0}; for (int i=0; i<14; i++) { cout << array[i] << " "; } cout << endl; for (int i=0; i<14; i++) { cout << array[i] << " "; } return 0; }``````
Last edited on
I would suggest you make a 2-D array.

By looking at your desired output, that array would be declared as such:
 `` `` ``int arr[14][7] = {{0}};``
........where 14 is the amount of numbers in a row, and 7 is the amount of numbers in a columns.

So the first 15 occurs at arr[1][4]......where 1 is the row, and 4 is the column. And you start counting at zero.

But if you just want to continue what you have:

Every for-loop, you cannot start from zero. If your first for-loop started at zero and ended at 13, then your second forloop should start at 14 and end at 28, your third forloop should start at 29 and end at 44, and so on...until you make a forloop that stops at 98.

Also, you should change your array values. For example, the first 15 occurs at array[18], the second 15 occurs at array[23], etc.

For those positions you want to do something like this: ` array[18] = 15;`.
Last edited on
Topic archived. No new replies allowed.