Creating a Table for n, sqrt n and ln n from 0 to nmax

  • Thread starter Thread starter stevenviney
  • Start date Start date
  • Tags Tags
    Ln Table
Click For Summary

Discussion Overview

The discussion revolves around creating a program that generates a table displaying values of n, sqrt(n), and ln(n) for integers from 0 to a user-defined maximum value, nmax. The focus is on programming techniques and implementation details in C++.

Discussion Character

  • Homework-related
  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant expresses difficulty in implementing a program to create a table and seeks guidance on how to apply the user-defined nmax.
  • Another participant questions the necessity of using an array to store values, suggesting that direct output to the screen may suffice.
  • A different participant advises that the current method of printing the table is incorrect and suggests using a loop to output each element individually.
  • One participant insists on the need for an array to list all values from 0 to n, indicating a preference for displaying the results in table form.
  • Another participant proposes using a spreadsheet program as an alternative solution for displaying the data.
  • One participant clarifies that printing the array directly outputs its memory address, not the contents, and suggests creating a function to handle the printing of a 2-dimensional array.
  • A participant shares a link to a sticky post that may provide additional helpful information.

Areas of Agreement / Disagreement

Participants express differing views on the necessity of using an array versus directly printing values. There is no consensus on the best approach to implement the table generation.

Contextual Notes

Participants have not resolved the specific programming issues, such as how to correctly implement the table display or the best data structure to use.

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

this is what i have so far

Code:
//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? I've spent hours and hours, I am sorry, I am so bad at this...

all i get out is 0x22cbd... :frown:
 
Technology news on Phys.org
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...
 
I don't think "count <<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).
 
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?
 
For what you are doing a spreadsheet program should suffice. OpenOffice.org Calc would do the trick or if you prefer M$ then Excel.
 
Internally, an array is just a pointer. So when you say:

count << 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)
 

Similar threads

Replies
12
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 66 ·
3
Replies
66
Views
6K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
12
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
12K