Results 1 to 2 of 2

Thread: confusing multidimensional arrays

  1. #1

    Thread Starter
    Frenzied Member markman's Avatar
    Join Date
    Nov 2000
    Location
    Florida.
    Posts
    1,197

    confusing multidimensional arrays

    Heres a problem I came up with to try and explain my real problem:
    Say I had a 5x5 grid of integers in an array (field[5][5]). The values are consecutive:
    Code:
    1   2   3   4   5 
    6   7   8   9   10
    11 12 13 14 15
    16 17 18 19 20
    21 22 23 24 25
    Now, since im trying to figure out what array element is what part in the grid, how would I output the number 6, 7, and 13, for example.
    retired member. Thanks for everything

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    Code:
    const outputnumber = /* Insert your number here */
    
    cout << field[outputnumber/5][outputnumber%5] << endl;  //Ahh! Almost forgot the ";"!
    Is this what you wanted?


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width