Chris B.
June 8th, 1999, 08:10 AM
My professor wants me to calculate the day of the week given a data. January and February are considered the 13th and 14th months of the previous year; March-December are considered the 3rd-12th months of the current year.
m = Month
d = Day
y = Year
n = worksum
n=d+2m+3(m+1)/5+y+y/4-y/100+y400+1
Will this work and how can I use it?
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.h>
int monthIn;
int yearIn;
const char MONTH_NAME [12][10]={"January","February","March","April","May",
"June","July","August","September",
"October","November","December"};
const int DAYS_IN_MONTH [12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
cout << endl << endl
<< "Please enter the following." << endl << endl;
//********************************************************
//The next few lines of code is where the user will input*
//the month and then the edit check begins. *
//********************************************************
cout << "Enter the number of the month (e.g. 1=Jan, 2=Feb, etc.): ";
cin >> monthIn;
while (monthIn < 1 || monthIn > 12)
{
cout << "\a Invalid month...Please enter a number from 1 to 12."
<< endl;
cout << "Enter the number of the month: ";
cin >> monthIn;
}
//********************************************************
//The next few lines of code is where the user will input*
//the year and then the edit check begins. *
//********************************************************
cout << "Enter the four digit year (e.g. 1999): ";
cin >> yearIn;
while (yearIn < 1000 || yearIn > 9999)
{
cout << "\a Invalid year...Please enter a year from 1000 to 9999."
<< endl;
cout << "Enter the four digit year: ";
cin >> yearIn;
}
clrscr();
cout << endl << endl << endl;
//********************************************************
//This is the algorithim that centers the month. *
//********************************************************
cout << setw ((80-strlen(MONTH_NAME[monthIn-1]))/2) << ""
<< MONTH_NAME[monthIn-1] << endl;
//********************************************************
//This is the loop that centers the year. *
//********************************************************
int count;
count=0;
while (count < 38)
{
cout << ' ';
count++;
}
cout << yearIn << endl << endl;
//********************************************************
//This is the loop that centers the seven days of the *
//week. *
//********************************************************
count=0;
while (count < 22)
{
cout << ' ';
count++;
}
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
//********************************************************
//The next statements are used to align the actual *
//days of the week (e.g. 1 thru 30). *
//********************************************************
int ioffset;
int offset = 1;
for (ioffset = 0; ioffset < offset; ioffset ++) cout << " ";
int daysInMonth = DAYS_IN_MONTH[monthIn - 1];
if (((yearIn % 4 == 0) && (yearIn % 100 !=0) && (yearIn % 400 != 0)) &&
(monthIn -1 == 1)) daysInMonth = 29;
for (count = 1; count <= daysInMonth; count ++)
{
if (count == 1 || ((count + offset -1) % 7 == 0))
cout << " ";
if (count < 10) cout << " " << count << "";
else
cout << " " << count << "";
if ((count + offset) % 7 == 0) cout << endl;
}
return 0;
}
m = Month
d = Day
y = Year
n = worksum
n=d+2m+3(m+1)/5+y+y/4-y/100+y400+1
Will this work and how can I use it?
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.h>
int monthIn;
int yearIn;
const char MONTH_NAME [12][10]={"January","February","March","April","May",
"June","July","August","September",
"October","November","December"};
const int DAYS_IN_MONTH [12]={31,28,31,30,31,30,31,31,30,31,30,31};
int main()
{
cout << endl << endl
<< "Please enter the following." << endl << endl;
//********************************************************
//The next few lines of code is where the user will input*
//the month and then the edit check begins. *
//********************************************************
cout << "Enter the number of the month (e.g. 1=Jan, 2=Feb, etc.): ";
cin >> monthIn;
while (monthIn < 1 || monthIn > 12)
{
cout << "\a Invalid month...Please enter a number from 1 to 12."
<< endl;
cout << "Enter the number of the month: ";
cin >> monthIn;
}
//********************************************************
//The next few lines of code is where the user will input*
//the year and then the edit check begins. *
//********************************************************
cout << "Enter the four digit year (e.g. 1999): ";
cin >> yearIn;
while (yearIn < 1000 || yearIn > 9999)
{
cout << "\a Invalid year...Please enter a year from 1000 to 9999."
<< endl;
cout << "Enter the four digit year: ";
cin >> yearIn;
}
clrscr();
cout << endl << endl << endl;
//********************************************************
//This is the algorithim that centers the month. *
//********************************************************
cout << setw ((80-strlen(MONTH_NAME[monthIn-1]))/2) << ""
<< MONTH_NAME[monthIn-1] << endl;
//********************************************************
//This is the loop that centers the year. *
//********************************************************
int count;
count=0;
while (count < 38)
{
cout << ' ';
count++;
}
cout << yearIn << endl << endl;
//********************************************************
//This is the loop that centers the seven days of the *
//week. *
//********************************************************
count=0;
while (count < 22)
{
cout << ' ';
count++;
}
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
//********************************************************
//The next statements are used to align the actual *
//days of the week (e.g. 1 thru 30). *
//********************************************************
int ioffset;
int offset = 1;
for (ioffset = 0; ioffset < offset; ioffset ++) cout << " ";
int daysInMonth = DAYS_IN_MONTH[monthIn - 1];
if (((yearIn % 4 == 0) && (yearIn % 100 !=0) && (yearIn % 400 != 0)) &&
(monthIn -1 == 1)) daysInMonth = 29;
for (count = 1; count <= daysInMonth; count ++)
{
if (count == 1 || ((count + offset -1) % 7 == 0))
cout << " ";
if (count < 10) cout << " " << count << "";
else
cout << " " << count << "";
if ((count + offset) % 7 == 0) cout << endl;
}
return 0;
}