I have a problem with initializing an array from within a class; all I'm trying to do is generate 7 random numbers preceding with the numbers in an array then seperate with comma's.
I have a version that works but I think it has poor coding.Code:#include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> using namespace std; class Create { public: Create() { Loop = 6; // did this because it doesnt allow me to // initialize int Loop = 6; in either public: or private: while(0 < Loop) { cout << Numbers[Loop]; for (int i = 0; i < 7; i++) { create[i] = (rand() %8) + 1; cout << create[i]; if ( i == 6) { cout << ","; } } Loop--; } } protected: int create[6]; int Loop; int Numbers[7] = {234803, 234805, 234802}; }; int main(int nNumberofArgs, char* pszArgs) { srand(time(0)); Create New; system("PAUSE"); return 0; }
Or, is there a way I could tell rand() to generate 7 random numbers in length.
Regards,
Richard Aberefa




Reply With Quote