# Writing a Table

1. Oct 27, 2006

### stevenviney

i need to write a program that sets up a table displaying values of n, sqrt n and ln n from n = 0 - nmax. Ive prompted the user to enter a value for integer nmax. but then ive no idea how to make this apply for the value for nmax for my table.

this is what i have so far

Code (Text):

//Problem Sheet 2 Table
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
const int numRows = n;
const int numColumns = 3;
double table[numRows][numColumns];
cout <<"This program will setup a table with values up to an integer n. Please enter your desired maximum integer n:"<< endl;
cin >> n;

cout <<table;

return 0;
}

how can i make nmax apply to the n i choose? and how can I set it up in a table which is displayed? ive spent hours and hours, im sorry, im so bad at this...

all i get out is 0x22cbd.....

2. Oct 27, 2006

### jpr0

Do you specifically need to store the values in an array?
If you only have to write them out onto the screen then there is no need for an array...

3. Oct 27, 2006

### robphy

I don't think "cout <<table;" is what you want (after you've built your table). You would want to loop through all of the elements in the array and send them (as scalars) to the stream... rather than sending the pointer to the table.

To build your table, you'd probably set up a for-loop from 0 to n and then calculate your values and place them in the table. As jpr0 mentioned, you may be able to skip the array altogether by immediately printing out the calculations for a particular value of i (0<=i<=n).

4. Oct 28, 2006

### stevenviney

hmm..

no i do need an array becaue i need to list all the values from 0 - n so i assumed it would needed to be displayed in table form?

5. Oct 28, 2006

### haki

For what you are doing a spreadsheet program should suffice. OpenOffice.org Calc would do the trick or if you prefer M\$ then Excel.

6. Oct 28, 2006

### Hurkyl

Staff Emeritus
Internally, an array is just a pointer. So when you say:

cout << table;

it prints the memory address where the array begins. As the others have said, you need to "manually" print each entry in the table.

Actually, if you're feeling up to it, you could write a function that takes a 2-dimensional array, as well as its dimensions, and does the printing... and then you could use that in the future when you want to print tables. (there will be some tricky language issues, though)

7. Oct 28, 2006