what code can I use to make a fortune cookie program that will give a random result when you input bday, month and year?

I'm new with this but this is what i typed first:

#include<conio.h>
#include<stdio.h>

main()
{
int dd,yy,mm;
clrscr();
printf("Know your Fortune Cookie reading");
printf("input birth day")
scanf("%d",&dd);
......
...
....

but idont know what formula to input to randomize my rsult since there are like over 20 readings i have.
im just familiar using If program
can i do that using this program\?

Edited 6 Years Ago by Nick Evan: Added code-tags

Using the stdlib.h header in conjunction with the time.h header you can generate pseudo-random numbers which will allow you to select a random fortune cookie.

#include <stdlib.h>
#include <time.h>

int main(void){
     srand( time(NULL) ); // seed the random generator, with current time, making it a different seed when run each time

     int myRandomValue = rand() % n; // returns a random number inclusive of the range 0..(n-1)
     
     return 0;
}

Since we are in the C++ forum lol, mistake by me. Make it ctime header and cstdlib :)

Chris

Edited 6 Years Ago by Freaky_Chris: n/a

Using the stdlib.h header in conjunction with the time.h header you can generate pseudo-random numbers which will allow you to select a random fortune cookie.

#include <stdlib.h>
#include <time.h>

int main(void){
     srand( time(NULL) ); // seed the random generator, with current time, making it a different seed when run each time

     int myRandomValue = rand() % n; // returns a random number inclusive of the range 0..(n-1)
     
     return 0;
}

Since we are in the C++ forum lol, mistake by me. Make it ctime header and cstdlib :)

Chris

ty and tell this to my co member.... i'll let them handle this...lol

This article has been dead for over six months. Start a new discussion instead.