### Generating set of months

How do I construct a random set of months using pointers? I've created the function but it seemed to be repeating itself in the set. How can I prevent that? What should I be inserting to my boolean function for check on the set?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167`` ``````const int MAX = 80; const int MAX_MONTHS = 12; enum Month { Jan, Feb, Mar, Apr, May, June, July, Aug, Sept, Oct, Nov, Dec }; Month getMonth(char[]); string displayMonth(Month); void constructSet(Month*, int); bool monthInSet (Month, Month*, int); void exampleOfSet() { int input; Month m[MAX]; cout << "--------------------------------------------" << endl; cout << "Here is an example on set of calendar months" << "\n" << "Set A = "; constructSet (m, MAX_MONTHS); } void constructSet (Month* m, int size) { int randMonth; m = new Month; *m = Jan; cout << "{"; for(int i = 0; i < size; i++) { if (i > 0) { cout << ","; } randMonth = rand() % MAX_MONTHS + 1; *m = Month(randMonth); string monthName = displayMonth(*m); cout << monthName; } cout << "}" << endl; } bool monthInSet (Month month, Month* m) { } Month getMonth(char garbage[]) { int i = 0; if (i == 0) { return Jan; } else if (i == 1) { return Feb; } else if (i == 2) { return Mar; } else if (i == 3) { return Apr; } else if (i == 4) { return May; } else if (i == 5) { return June; } else if (i == 6) { return July; } else if (i == 7) { return Aug; } else if (i == 8) { return Sept; } else if (i == 9) { return Oct; } else if (i == 10) { return Nov; } else if (i == 12) { return Dec; } } string displayMonth(Month m) { string monthName; switch(m) { case Jan: monthName = "Jan"; break; case Feb: monthName = "Feb"; break; case Mar: monthName = "Mar"; break; case Apr: monthName = "Apr"; break; case May: monthName = "May"; break; case June: monthName = "June"; break; case July: monthName = "July"; break; case Aug: monthName = "Aug"; break; case Sept: monthName = "Sept"; break; case Oct: monthName = "Oct"; break; case Nov: monthName = "Nov"; break; case Dec: monthName = "Dec"; break; } return monthName; } ``````
closed account (Dy7SLyTq)
you need to seed rand

srand((unsigned) time(NULL));
Topic archived. No new replies allowed.