Site hosted by Angelfire.com: Build your free website today!

Program 19 

 

 

 


Write a program to determine the day of the week a person was born given his or her birth date. The following steps should be used to find the day of the week corresponding to any date in this century.

  1. Divide the last two digits of the birth year by 4. Put the quotient (ignoring the remainder) in total. For example, if the person was born in 1983, divide 83 by 4 and store 20 in total.
  2. Add the last two digits of the birth year to total.
  3. Add the last two digits of the birth date to total.
  4. Using the following table, find the “month number” and add it to total.

Picture - The Red Robot fighting Black Robot

January = 1

February = 4

March = 4       

April = 0

May = 2

June = 5

July = 0

August = 3

September = 6

October = 1

November = 4

December = 6

                                                                        ROBOT BATTLE!!!

  1. If the year is a leap year and if the month you are working with is either January or February, then subtract 1 from the total.
  2. Find the remainder when total is divided by 7. Look up the remainder in the following table to determine the day of the week the person was born. Note that you should not use this procedure if the person’s year of birth is earlier than 1900.

1 = Sunday     

2 = Monday

3 = Tuesday

4 = Wednesday                                              “Know what’s funny? Your face!”

5 = Thursday                                                   (note: this is not necessarily intended to insult

6 = Friday                                                        those with funny looking faces)

0 = Saturday

 

Typical input is

 

5-15 78

 

where the first entry (5-15) represents the birth date (May 15) and the second entry (78) represents the birth year. An appropriate error message should be printed if a person’s year of birth is before 1900.