Thread: need help with for looping two-dimensional array

  1. #1
    Registered User
    Join Date
    Oct 2005

    need help with for looping two-dimensional array

    Hi im trying to write a function which takes the value of an array from a class with custnum variable and compares it with the other values of the array

    lets say if i have 4 custnum ids...and index 0 and 1 of STORE1.custnum is equal it would store those two values in tmp[0][0] and tmp[0][1] ..and to check if STORE1[2].custnum is equal to the previous entries it would compare 2 with 1 with 0. if it is not equal the value will be stored in tmp[1][0]....then we check for STORE1[3].custnum by comparing 3,2 3,1 3,0 index of custnum if it is equal to index 2 it would store it in tmp[1][1] and so on...

    how would i go about doing this in a loop
    the size of the array of custnum is y.

    for example this code only checks the STORE1[0].custnum and STORE1[1].custnum values
    // sets initial value
         tmp[0][0].custnum = STORE1[0].custnum;
         tmp[0][0].product = STORE1[0].product;
         tmp[0][0].quantity = STORE1[0].quantity;
         tmp[0][0].month = STORE1[0].month;
         tmp[0][0].day = STORE1[0].day;
         tmp[0][0].year = STORE1[0].year;
    // compares custnum of 0 and 1 index   
         if(tmp[0][0].custnum = STORE1[1].custnum)
         tmp[0][1].custnum = STORE1[1].custnum;
         tmp[0][1].product = STORE1[1].product;
         tmp[0][1].quantity = STORE1[1].quantity;
         tmp[0][1].month = STORE1[1].month;
         tmp[0][1].day = STORE1[1].day;
         tmp[0][1].year = STORE1[1].year;
         else {
         tmp[1][0].custnum = STORE1[1].custnum;
         tmp[1][0].product = STORE1[1].product;
         tmp[1][0].quantity = STORE1[1].quantity;
         tmp[1][0].month = STORE1[1].month;
         tmp[1][0].day = STORE1[1].day;
         tmp[1][0].year = STORE1[1].year; }

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Something like
    for(int x = 0; x < whatever; x ++) {
        array[x] = something;

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Oct 2005
    i think that just fills the array to what u want it to be

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Replies: 5
    Last Post: 11-20-2001, 11:48 AM
Website Security Test