# Thread: 2 Dimensional array question/problem

1. ## 2 Dimensional array question/problem

I am working on a program in C++ where the user enters a start number and a skip value. The program is then suppose to display 100 numbers (starting at the start value) and increase by the skip value. (ex. start number = 10, skip number = 5, output would be 10 15 20... until 100 numbers were outputed).

here is what i have so far, and maybe some one could steer me back in the right direction:

void array()
{
int array[10][10];
int start_value;
int skip_value;
int row;
int col;
cout << "Please enter a starting value: ";
cin >> start_value;
cout << "Please enter a skip value: ";
cin >> skip_value;

array[0][0] = start_value;
cout << array[0][0] << " ";

for (row = 0; row <= 9; row++)
{
for (col = 0; col <= 9; col++)
{
array[row][col] = array[row][col] + skip_value;
cout << array[row][col] << " ";
}

row++;
col = 0;
}

}

if anyone can help me out it would be much appreciated.

thanks

2. First of all, use code tags. Second, why do you need a two dimensional array for this? I'd do something like this:
Code:
```for(int i = start; i < 100*skip; i+=skip)
cout << i << endl;```
I think that would suffice. I'm not entirely sure that that would only print out the first 100 numbers, as this was coded off the top of me head, but I think you get the idea. Try to find simple, elegant solutions rather than going overboard with multi-dimensional arrays and such.

3. There isn't any reason that I can see why you would need an array, let alone a two dimensional array. You only need an array to store data which isn't needed here.

Try something like
Code:
```for (int x=0; x<100; ++x)
{
cout<<start_value+(x*skip_value)<<endl;
}```