Code:
// COPchapter5Assignment.cpp : Defines the entry point for the console application.
//
/* this program will calculate a person's age based on the current year and person's birthdate then print results.*/
#include "stdafx.h"
//function declarations
void getBirthDate(int* birthDay, int* birthMonth, int* birthYear);
void getCurrentDate(int* currentDay, int* currentMonth, int* currentYear);
int calculateAge(int currentYear,int birthYear, int currentMonth, int birthMonth, int currentDay, int birthDay);
void printResults(int birthYear, int birthMonth, int birthDay, int currentYear, int currentMonth, int currentDay);
int main(void)
{
//local declarations
int birthYear;
int birthMonth;
int birthDay;
int currentDay;
int currentMonth;
int currentYear;
int age;
//statements
getBirthDate(&birthDay, &birthMonth, &birthYear);
getCurrentDate(¤tDay, ¤tMonth, ¤tYear);
calculateAge(currentYear,birthYear, currentMonth, birthMonth, currentDay, birthDay);
printResults (birthYear, birthMonth, birthDay, currentYear, currentMonth, currentDay);
return 0;
} //main
/* ===================================getBirthDate=============================
This function reads the birthYear input by the user at the keyboard
Pre parameter save the dates as integer values in birthYear, birthMonth and birthDay
Post Data read into parameter address
*/
void getBirthDate(int* birthDay, int* birthMonth, int* birthYear)
{
//statements
printf("Please Enter your birth date in dd, mm, yyyy format: \n");
scanf_s("%d %d %d",birthDay,birthMonth,birthYear);
return ;
} //getbirthYear
/* ===================================getCurrentDate=============================
This function reads the Current input by the user at the keyboard
Pre parameter save the dates as integer values in birthYear, birthMonth and birthDay
Post Data read into parameter address
*/
void getCurrentDate(int* currentDay, int* currentMonth, int* currentYear)
{
//statements
printf("Please Enter the current date in dd, mm, yyyy format: \n");
scanf_s("%d%d%d",currentDay,currentMonth,currentYear);
return ;
} //getCurrentDate
/* ==================================CalculateAge=============================================
this function will calculate an age based on the two dates given
pre
Post returns age
*/
int calculateAge(int currentYear, int birthYear, int currentMonth, int birthMonth, int currentDay, int birthDay)
{
//local declarations
int age;
//Statements
age = currentYear - birthYear;
if (currentMonth < birthMonth)
age--;
else if (currentMonth > birthMonth)
age = age;
else if (currentMonth == birthMonth & currentDay < birthDay)
age--;
else
age=age;
printf("you are %d\n");
return age;
} //calculateAge
/* =======================================printResult=====================================================
prints the current date, birthdate and person's age
*/
void printResults(int birthYear, int birthMonth, int birthDay, int currentYear, int currentMonth, int currentDay)
{
//local declarations
//statements
printf("Your birthday is %d,%d,%d\n", birthDay, birthMonth, birthYear);
printf("The current date is %d,%d,%d\n", currentDay,currentMonth, currentYear);
printf("you are %d\n", age);
return ;
} // printResult