I am fairly new to C++ and am having trouble with usign structs in 2D arrays. I am modelling a physical storage rack (3 rows high, 14 colums long) as an array. So I have declared my array in the following way:

// Declare a 3x14 array const int nNumRows = 3; const int nNumCols = 14; int nStorageRack[nNumRows][nNumCols]= { 0 };[/color]

I need each element to hold a roll of steel, which will be represented by a struct in the following form:

struct SteelData { char chGrade; //type of steel float fWidth; // width of roll float fLength; //length when unrolled bool bEmpty; //is the element occupied? 1=yes 0=no };

I will have 6 grades of steel, with 2 different lengths of each. So that gives me a total of 12 different sets of struct data. Is it possible to fill the array with structs, but without any data other than the bool variable being false? So like it will have the chGrade variable there... which i can then edit the members individually with a command like:

nStorageRack[Row][Col].fWidth = 1.85;

I found an example that did the multiplication of elements in a 2D array, and adapted it for my array size:

// Calculate a multiplication table for (int nRow = 0; nRow < nNumRows; nRow++) { for (int nCol = 0; nCol < nNumCols; nCol++) { nStorageRack[nRow][nCol] = nRow * nCol; //if(nCol != 0 && nRow != 0) cout << nStoragerack[nRow][nCol] << "\t"; } //if(nRow != 0) cout << endl; }

Im guessing i will be doing something similar with nested for loops to fill it with structs. but can someone give me a few pointers how to go about doing this.

Any help is appreaciated

Many Thanks

MOD EDIT: When posting code...USE CODE TAGS!!!

This post has been edited by **JackOfAllTrades**: 08 November 2010 - 09:41 AM