### Enumerations in Array

Could anyone please assist me in incorporating my enumerations with my arrays? I've tried putting it in, but the for-loops don't work. I put it in the "total t-shirt" loop.

Thanks!

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081`` ``````#include #include #include using namespace std; enum SIZE {S, M, L, XL}; enum COLOR {RED, BLACK, BLUE, GREEN}; int input(istream& in=cin) { int x; in >> x; return x; } int main () { time_t P; time (&P); cout << "Today's time and date is: " << ctime(&P) << endl; int t[4][4]; //Copy data from "invt.txt" into array t fstream f; f.open ("invt.txt", ios::in); for (int i = 0; i < 4; ++i) { for(int j = 0; j < 4; ++j) { t[i][j] = input(f); } } //Display array t for (int row = 0; row < 4; ++row) { for (int col = 0; col < 4; ++col) { cout << t[row][col] << '\t'; } cout << endl; } cout << endl; //Compute and print the total number of all tee shirts int TotalAll=0; for(COLOR row=RED; row
 ``123456789`` `````` //for(COLOR row=RED; row
It works! Thank you for your help!
This would be more consistent:

 ``12`` ``````enum SIZE {S, M, L, XL, NSIZES }; enum COLOR {RED, BLACK, BLUE, GREEN, NCOLOURS };``````

And then:

 ``12345678910111213141516171819`` ``````int t[NCOLOURS][NSIZES]; // Copy data from "invt.txt" into array t // fstream f; // f.open ("invt.txt", ios::in); { // restrict the life of the stream object ifstream f( "invt.txt" ) ; // prefer using a std::ifstream for input for( COLOR clr = RED ; clr < NCOLOURS ; clr = COLOR(clr+1) ) { for( SIZE sz = S ; sz < NSIZES ; sz = SIZE(sz+1) ) { t[clr][sz] = input(f); } } } // the ifstream is destroyed // etc ... ``````

Alternatively, if you want to avoid the casts

 ``1234567`` `````` for( int row = RED ; row <= GREEN; ++row ) { for( int col = S ; col <= XL ; ++col ) { TotalAll += t[row][col]; } }``````

Andy
Topic archived. No new replies allowed.