2D array formatting

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int main()
{
  double tbl[100][100];
  double *dp = &(tbl[0][0]);
  for(int i = 0; i < 100; i++)
	   dp[i] = i;
   
   //table set up and loaded.  its a 5 x 20 for example. 
   int rows = 5; int cols = 20;
  for(int i = 1; i <= rows*cols; i++) //start at 1 because %0 == 0
  {
	cout << dp[i-1]<< " "; //index -1 because started at 1
	if(i%cols == 0) cout << endl;
  }	
}
you put your own values into the table with something like
cin >> value;
table[somerow][somecol] = value;

You are not dense. I did some magic to collapse your 2-d table to 1-d. % is remainder, called modulo or modulus in coder speak. So 1 divided by 20 is 0, remainder 1. 2 divided by 20 is 0, remainder 2. … 20 divided by 20 is 1, remainder 0… so it splits out the rows and columns in the print with that idea.

what I gave you will print it split out into rows and columns. Take my little example program, and play with it. Then apply it to yours.

you can explicitly do it with 2 loops.
for(r =0; r < rows; r++)
{
for(c = 0; c< cols; c++)
cout << array[r][c] <<" ";
cout << endl; //this is in the outer loop, not the inner, no {} group.
}
that may be easier to understand.

54 looks like it should be the assignment though.
so maybe in that loop you want
table[ta][v] = result of big equation;

is that what you need? you don't start your TA and V at zero, though... I really don't know where in the table you want an entry to go? Somehow you need to figure out integer index into rows/cols of the table as a place to put a particular entry, and then put it there.
Last edited on
.
LOL
Last edited on
oh whee, another rage-quit poster.
Topic archived. No new replies allowed.