/* lottery.cpp * Anthony Larrain * Spring 2006, csc309 * * Program will generate 6 distinct integers in the range * [1,UPPER], where UPPER is a global variable equal to 53 * */ // for rand() and srand() #include // for time() #include #include #include // for ostringstream class. #include using namespace std; string quickPick(); string toString(bool lotto []); const unsigned int UPPER = 52; const unsigned int COUNT = 6; int main(){ cout << "Your lotto numbers are ... " << endl; cout << quickPick() << endl; system("pause"); return 0; } string quickPick(){ srand(time(NULL)); // using initalizer list // itialize all cells to false bool lotto [UPPER + 1] = {false}; for(int i = 0; i < COUNT;){ int rnum = rand() % UPPER + 1; if(lotto[rnum] != true){ lotto[rnum] = true; ++i; } } return toString(lotto); } string toString(bool lotto [] ){ const char space = ' '; ostringstream numbers; for(int i = 1; i < UPPER + 1; i++){ if(lotto[i]){ numbers << i << space; } } return numbers.str(); }