COSC 1315 - Fundamentals of Programming
Allan Kochis

Homework Assignment Extra Credit


How old?


Write a program prompts a person to enter their birthday. It then would tell them how many days they have lived to the current day.

Use GetLocalTime to obtain the current date and time illustrated in the following program.

#include <iostream>
#include <windows.h>
 
using namespace std;
 
int main()
{
 SYSTEMTIME time;
 
 GetLocalTime(&time);
 
 cout << time.wMonth << endl;
 cout << time.wDay << endl;
 cout << time.wYear << endl;
        system("pause");
        return 0;
}

Today is 1/11/2010 Hi what is your name? :Garrett In what year were you born? :2001 In what month? :9 What day? :29 Garrett, you have lived 3026 days Press any key to continue . . .
Today is 1/11/2010 Hi what is your name? :Unix In what year were you born? :1970 In what month? :1 What day? :1 Unix, you have lived 14620 days Press any key to continue . . .
Today is 1/11/2010 Hi what is your name? :Dwight In what year were you born? :1897 Sorry I can't do years before 1900 Press any key to continue . . .
Today is 1/11/2010 Hi what is your name? :Zeb In what year were you born? :1950 In what month? :14 Lets try again : In what month? :13 Lets try again : In what month? :11 What day? :11 Zeb, you have lived 21611 days Press any key to continue . . .
Today is 1/11/2010 Hi what is your name? :Winnie In what year were you born? :1999 In what month? :2 What day? :30 Lets try that again What day? :29 Lets try that again What day? :28 Winnie, you have lived 3970 days Press any key to continue . . .
Today is 1/11/2010 Hi what is your name? :Tigger In what year were you born? :2000 In what month? :2 What day? :30 Lets try that again What day? :29 Tigger, you have lived 3604 days Press any key to continue . . .