Random?

Amorssang1

BSOD
Messages
358
Alright, so I'm not to familar with c++ and I was wondering how I could get a random "Month" date for this....

#include <iostream>
using namespace std;

int main ()
{
int num1, num2, total;

cout << "Enter Your Birth Year: ";
cin >> num1;
cout << "Now Enter The Current Year: ";
cin >> num2;
total = num1 + num2;
cout << "Your Doom Date is September 5th Year " << total;

return 0;
}

What I want to do is make the "September" change randomly everytime you enter a new set of numbers. So it would change around....how would I do this? I'm sure it's possible...
 
You'd need to set up a way to interpret the numbers 1 to 12 as month names, use the srand(time(NULL)) statement in main, called ONCE to seed the random number generator. Then use ((rand()%11)+1) [I think that will generate 1 to 12!?] to get the number and replace a string variable with the resulting month name for display. I beleive srand and rand are included in cstdlib and you will need time or time.h for the time call used to seed the random generator.
 
Back
Top Bottom