hi all, i needed to write a small fortune program for class using random numbers. the only thing is that the only random number im getting is 2. thanks for the help!
Code:#include <stdlib.h> #include <stdio.h> int main() { int randomNum = 0; char answer; printf ("Do you want to see your fortune?"); scanf ("%c", &answer); if (answer == 'y' || answer == 'Y') { randomNum = rand() % 4 + 1; if (randomNum == 1 ) { printf ("You will learn something today.\n\n"); } else if (randomNum == 2 ) { printf ("You will enjoy a long and happy life.\n\n"); } else if (randomNum == 3 ) { printf ("Opportunity knocks softly. Can you hear it?!\n\n"); } else { printf ("You will be financially rewarded for your hard work.\n\n"); } } else { printf ("You will be forever unlucky.\n\n"); } system ("PAUSE"); return 0; }