1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include "Functions.h"
using namespace std;
int main()
{
//Find current date
SYSTEMTIME systime;
GetSystemTime(&systime);
int curYear = systime.wYear;
int curMonth = systime.wMonth;
int curDay = systime.wDay;
int curHour = systime.wHour;
int curMinute = systime.wMinute;
int curSecond = systime.wSecond;
//Setup birthday variables
int monthBorn, dayBorn, yearBorn;
cout << "What month were you born (1-12): ";
cin >> monthBorn;
cout << "What day were you born (1-31): ";
cin >> dayBorn;
cout << "What year were you born: ";
cin >> yearBorn;
//Initialize all DaysLeftInYear() variables
int daysPassedCur = 0;
int daysPassedBor = 0;
//Calculate how much time has passed in the CURRENT year
DaysLeftInYear(curYear, curMonth, curDay, daysPassedCur);
DaysLeftInYear(yearBorn, monthBorn, dayBorn, daysPassedBor);
//Initialize all TimePassed() variables
int daysPassed = 0;
int yearsPassed = 0;
int hoursPassed = 0;
int minutesPassed = 0;
int secondsPassed = 0;
//Calculate how much time has passed DISREGARDING the current year
TimePassed(yearBorn, curYear, monthBorn, curMonth, dayBorn, curDay, daysPassedBor,
daysPassed, yearsPassed, hoursPassed, minutesPassed, secondsPassed, daysPassedCur);
#ifdef DEBUGMAIN_CODE
cout << " -DEBUG- " << endl;
cout << "main() Values" << endl;
cout << "-------------------" << endl;
cout << "curYear: " << curYear << endl;
cout << "curMonth: " << curMonth << endl;
cout << "curDay: " << curDay << endl;
cout << "curSecond: " << curSecond << endl;
cout << "monthBorn: " << monthBorn << endl;
cout << "yearBorn: " << yearBorn << endl;
cout << "dayBorn: " << dayBorn << endl;
cout << "daysPassedCur: " << daysPassedCur << endl;
cout << "daysPassedBor: " << daysPassedBor << endl;
cout << "daysPassed: " << daysPassed << endl;
cout << "yearsPassed: " << yearsPassed << endl;
cout << "hoursPassed: " << hoursPassed << endl;
cout << "minutesPassed: " << minutesPassed << endl;
cout << "secondsPassed: " << secondsPassed << endl;
#endif
int theChoice = OurMenu();
PrintAge(theChoice, yearsPassed, daysPassed, daysPassedBor - daysPassedCur, hoursPassed, curHour,
minutesPassed, curMinute, secondsPassed, curSecond, curYear);
return 0;
}
void PrintAge(int choice, int totalYears, int totalDays, int daysSinceYear, int totalHours, int hoursSinceDay,
int totalMinutes, int minutesSinceHour, int totalSeconds, int secondsSinceHour, int curYear)
{
enum Choice { YEARS = 1, DAYS, HOURS, MINUTES, SECONDS };
if (daysSinceYear >= 365)
{
daysSinceYear %= 365;
totalYears++;
}
switch(choice)
{
case YEARS:
cout << "You are " << totalYears << " years, " << daysSinceYear << " days, "
<< hoursSinceDay << " hours, " << minutesSinceHour << " minutes, and "
<< secondsSinceHour << " seconds old." << endl;
break;
case DAYS:
cout << "You are " << totalDays << " days, " << hoursSinceDay << " hours, "
<< minutesSinceHour << " minutes, and " << secondsSinceHour
<< " seconds old." << endl;
break;
case HOURS:
cout << "You are " << totalHours << " hours, " << minutesSinceHour <<
" minutes, and " << secondsSinceHour << " seconds old." << endl;
break;
case MINUTES:
cout << "You are " << totalMinutes << " minutes and " << secondsSinceHour
<< " seconds old." << endl;
break;
case SECONDS:
cout << "You are " << totalSeconds << " seconds old." << endl;
break;
default:
cout << "ERROR!" << endl;
break;
}
}
int OurMenu()
{
int myChoice = 0;
cout << "----------Birthday Menu----------" << endl;
cout << "[1] Regular output" << endl;
cout << "[2] Total days" << endl;
cout << "[3] Total hours" << endl;
cout << "[4] Total Minutes" << endl;
cout << "[5] Total Seconds" << endl;
cin >> myChoice;
return(myChoice);
}
|