arrays and functions

Okay, im kinda new to this c++ program and all.
One question is how do you make a 2D array(table) using arrays and functions
eg:
_ _____|______|________________________
0| | |
1| | |
2| | |
3| | |
4| | |

it has a fixed column of 5
and the number of rows(0,1,2,3,4) is determined by the value the user enters...

much appreciated
What do you have problem with? Creating data sructure? Or outputting it? What have you tried?
I've used a nested for loop to firstly create the table:
but its not outputting what i want...

this is the nested loop im using

#include <iomanip>
#include <cstdlib>

using namespace std;


int main()
{
const int N=7;
int months;


cout<<"Enter number of months:";
cin>>months;

int table[months][N];

for(int i = 0; i<= months;i++)
{
cout<<i<<endl;


for(int j = 0; j < N;j++)
{
cout<<"sector#"<<j;


//cout<<table[i][j]<<endl;
}

}

What i want is to display the rows from 0 to the number the user enters. eg
if he enters 10
then:
0
1
2
3
4
5
6
7
8
9
10

this part is fine
, using a for loop but, i want the table to have just a single column, consisting of 5 elements.

what i want is something like this:
|Title |Title |Title |Title |
---------------------------------
0|
1|
2|
3|
4|
5|
6|
7|

thnax in advance

Last edited on
Topic archived. No new replies allowed.