hi... im a bit new to this forum. i saw it on google and decided to join up...
im working on a calender like program for my computer science 102 course. the parameters are as follows:
Make a program that, when given the mm/dd/yyyy, can decide what DAY the user is referring to. so for example if i input 10/31/2004 the output would look like this:
"That day is a Sunday!"
and so forth.
right now im stuck at leap years.... i need help on writing an if statement on how to determine leap years.... my program compiles and runs fine until i try some leap year.... i asked my teacher for help but the only thing she said was that "a leap year is NOT NECESSARILY EVERY 4 YEARS". any suggestions? ill post my code so you can see what im working with. oh im using dev c++ as my editor if that matters.
/* This program does XXXX */
#include <iostream>
using namespace std;
void getData(int&, int&, int&);
int findYear(int);
void calculate(void);
int calculateMonthDays(int);
void calculateBornDay(int, int, int);
int main ()
{
calculate();
system("pause");
return 0;
}
void calculate ()
{
int month;
int day;
int year;
int lastDayDec;
int monthDays;
//cout << " in main\n";
getData(month, day, year);
lastDayDec = findYear(year);
monthDays = calculateMonthDays(month);
calculateBornDay(lastDayDec, monthDays, day);
//cout << month << "/" << day << "/" << year << "\n";
//cout << "*** ***" << lastDayDec << "*** ***" << monthDays;
//cout << "*** ***" << monthDays;
//calculate();
return;
}
void getData(int& month, int& day, int& year)
{
cout << "Enter the month in which you were born: ";
cin >> month;
cout << "\nDay: ";
cin >> day;
cout << "\nYear: ";
cin >> year;
return;
}
int calculateMonthDays(int month)
{
int days = 0;
month = month - 1;
switch (month)
{
case 12 : days = days + 31;
case 11 : days = days + 30;
case 10 : days = days + 31;
case 9 : days = days + 30;
case 8 : days = days + 31;
case 7 : days = days + 31;
case 6 : days = days + 30;
case 5 : days = days + 31;
case 4 : days = days + 30;
case 3 : days = days + 31;
case 2 : days = days + 28;
case 1 : days = days + 31;
default : days = days + 0;
}
//cout << "\n " << days << "\n";
return days;
}
int findYear(int year)
{
int temp1, temp2, temp3, temp4, temp5, temp6;
int answer;
temp1 = (year - 1);
temp2 = temp1 * 365;
temp3 = year - 1;
temp4 = temp3 / 4;
temp5 = temp3 / 100;
temp6 = temp3 / 400;
answer = (temp2 + temp4 - temp5 + temp6) % 7;
//cout << "\n*********" << answer << "\n";
return answer;
}
void calculateBornDay(int lastDayDec, int monthDays, int day)
{
int bornDay;
bornDay = (lastDayDec + monthDays + day) % 7;
if (bornDay == 0)
cout << "You were born on a Sunday.\n";
else if (bornDay == 1)
cout << "You were born on a Monday.\n";
else if (bornDay == 2)
cout << "You were born on a Tuesday.\n";
else if (bornDay == 3)
cout << "You were born on a Wednesday.\n";
else if (bornDay == 4)
cout << "You were born on a Thursday.\n";
else if (bornDay == 5)
cout << "You were born on a Friday.\n";
else if (bornDay == 6)
cout << "You were born on a Saturday.\n";
}
so basically i just need a formula to figure out leap years... and leap years are NOT necessarily every 4 years... help plz?