Nasty file with all the prototypes, functions and main in it
/* File: projmine.c
* Author: Margot (mmckin1@umbc.edu)
* Date: 20 February 2001
* SSN: None of Your Business!
* Section: Mine
*
* This program takes the users birthday in 6 digit mmddyy
* format and uses it to seed the random number generator.
* Once the generator is seeded with the users birthday,
* it will produce the desired set of "lucky" numbers
* consistently for the user.
*
* This may or may not conform to your class coding standards.
* See the main course webpage to be sure what those
* standards are.
*/
#include
/* Function Prototypes */
int GetValidBDay (void);
int InValidDate(int date);
void SeedRand (int seed);
void PrintNRandNums (int n);
void PrintGreeting (void);
main() {
int date, totNum;
PrintGreeting();
/* Priming Read */
date = GetValidBDay();
/* Sentinel Value is 0 to quit the program. While they
* don't want to quit. */
while(date != 0) {
SeedRand(date);
printf("How Many Lucky Numbers Do You Need? ");
scanf("%d", &totNum);
PrintNRandNums(totNum);
date = GetValidBDay();
}
}
/* Function: PrintGreeting()
*
* This function prints a little synopsis of the program
* out to the screen for the user.
*/
void PrintGreeting (void) {
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("A recent discovery has been made connecting your birthday to\n");
printf("your winning Lottery numbers. Here is a program to get your\n");
printf("personal lucky numbers. Enter in your Birthday as a 6 digit\n");
printf("number (this program assumes that you can handle this in an\n");
printf("error-free style). Enter 0 will quit the program.\n");
printf("\n\t\t\tHave fun!!!\n\n");
printf("WARNING: You may get repeats! Other people have to have\n");
printf(" some numbers to be lucky with too!!\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
return;
}
/* Function: GetValidBDay
*
* GetValidBDay gets a (hopefully) 6 digit number from
* the user. This function calls InValidDate to be sure
* that the date the user entered was correct and gets
* a new number from them otherwise.
*/
int GetValidBDay (void) {
int date;
printf("\nPlease enter your Birthday (mmddyy) or 0 to Quit: ");
scanf("%d", &date);
while( date != 0 && InValidBDay(date) ) {
printf("You don't know your own Birth Date?!?!?!?!?!\n");
printf("\nPlease enter your Birthday (mmddyy) or 0 to Quit: ");
scanf("%d", &date);
}
return(date);
}
/* Function: InValidBDay
*
* InValidBDay is a predicate function which returns
* true (1) if the date is not within the specified
* limits and false (0) otherwise.
*/
int InValidBDay (int date) {
int month, day;
/*Strips the year off... they are all valid. */
date /= 100;
/* Take advantage of truncation in integer division to
* get the first two digits of the total date which will
* represent the month. */
month = date / 100;
if( month < 1 || month > 12 ) {
return 1;
}
/* Mod the date by 100 to strip out the last two digits
* is th remaining date which represent the day. check
* to be sure the day is within the proper scale of days
* available per month. */
day = date % 100;
if( day <= 0 ) {
return 1;
}
switch(month) {
case 1: case 3: case 5:
case 7: case 9: case 10:
case 12:
if( day > 31 ) {
return 1;
}
case 8: case 4: case 6:
case 11:
if( day > 30 ) {
return 1;
}
case 2: /* We are assuming that February */
if( day > 28 ) { /* is not affected by leap years */
return 1; /* I write it; I can do that. */
}
default:
return 0;
}
}
/* Function: SeedRand
*
* This function seeds the random number generator with
* the integer passed and returns nothing.
*/
void SeedRand (int seed) {
srand(seed);
return;
}
/* Function: PrintNRandNums
*
* This function prints the n (being the arguement passed)
* random numbers to the screen in 5 beautiful columns.
* If the user has chosen for either 0 or a negative
* number of integers to be printed they are publicly
* humiliated.
*/
void PrintNRandNums (int n) {
int i, curr;
if( n <= 0 ) {
printf("\nNo Lucky Numbers for You!!!\n");
return;
}
for( i = 0; i < n; i++ ) {
/* Print a new line after 5 entries have been printed
* creating 5 columns. */
if( i % 5 == 0 ) {
printf("\n");
}
curr = rand() % 100;
printf("\t%d", curr);
}
printf("\n");
return;
}