Thread: 2 Dimensional array question/problem

  1. #1
    Registered User
    Join Date
    Jan 2003

    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] << " ";

    col = 0;


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


  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Phildelphia, PA
    First of all, use code tags. Second, why do you need a two dimensional array for this? I'd do something like this:
    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.

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    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
    for (int x=0; x<100; ++x)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  2. How To pass 2 dimensional array of strings to a function
    By chottachatri in forum C Programming
    Replies: 15
    Last Post: 01-25-2008, 02:20 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 01:01 AM
  4. Replies: 5
    Last Post: 11-20-2001, 12:48 PM