Assignment Instructions

  1. Edit, compile, and run the following program on the UH UNIX shell:
    1. Make sure you use these in your program: symbolic constants, double, int, type casting, conversion (format) specifiers, and puts() function.
    2. Ask the user to enter the day, month, and year they were born.
    3. Use function getdouble() to get the dates from the user.
    4. The function getdouble() requires the use of files getdouble.c and getdouble.h and alterations to the makefile makefile-double.
    5. DON'T FORGET TO ADD THIS HEADER FILE to the top of your program, or function getdouble() will not return the correct value:
      #include "getdouble.h"
    6. Display the current date. You can use the assignment due date as the current date.
    7. Calculate the user's age in days.
      1. The easiest way to do this is to calculate the number of days since year 1 for today's date and the birthdate, then subtract the number of days since year 1 for the birthdate from the number of days since year 1 for today's date.
      2. Calculate the number of days since year 1 for the current date by: (1) multiplying the year by 365.25 to account for leap years every four years, (2) subtract one from the month (so September would be 9 - 1 = 8) and multiply this by 365.25/12.0, and (3) adding both results to the day of the month.
      3. Example formula: days = (year * 365.25) + ((month - 1) * 365.25 / 12.0) + day
      4. Calculate the number of days since year 1 for the birthdate by: (1) multiplying the year by 365.25 to account for leap years every four years, (2) subtract one from the month and multiply this by 365.25/12.0, and (3) adding both results to the day of the month.
      5. You can check your calculations by using this website: Age Calculator.
      6. Don't worry if your calculations are off by a few days.
      7. OPTIONAL: When you display the user's age in days, put a comma in the 1000s place by separating the number into two parts using division and modulus by 1000. In other words, the 1000s place is calculated by totalDays/1000. The first three digits are calculated by totalDays%1000. To include extra zeros on integers, use .3 precision as shown in format.c.
      8. Otherwise, just print out the number of days without the comma.
    8. Email your makefile and C program to the instructor.

Example I/O

Here is example input and output from three different birthdays. This is from running the same program three times. In other words, you just have to ask the user one time for their month, day, and year. You do not need to ask three times. You can use the output below to test your code three times.

This program will calculate your age in days.
Enter the month you were born: 7
Enter the day you were born: 1
Enter the year you were born: 2005
Today's date is: 9/1/2016
Your age in days is: 4,078

This program will calculate your age in days.
Enter the month you were born: 7
Enter the day you were born: 30
Enter the year you were born: 1975
Today's date is: 9/1/2016
Your age in days is: 15,007

This program will calculate your age in days.
Enter the month you were born: 10
Enter the day you were born: 3
Enter the year you were born: 1950
Today's date is: 9/1/2016
Your age in days is: 24,074