/* Program to Calculate the Day of the week given a date
** COMP 1102
** Date of last modification: Feb 26, 2011
** Programmer:
**/
// Pull in includes
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
// local function declarations
int convDay( int d, int m, int y );
const char *day_names[ ] =
{
"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"
};
int main()
{
int d = 0, m = 0, y = 0, day = 0;
system("cls"); // clears the output screen
cout << endl; // send a "end of line" or "new line"
// symbol to the output stream (screen)
cout << "Provided with your date of birth, we are going to determine\n\r"
"The day you were born in history. Please provide all input in numeric form.\r\n\r\n";
cout << "What month were you born? ";
cin >> m;
cout << "What day were you born? ";
cin >> d;
cout << "What year were you born? ";
cin >> y;
// Find and return the day
day = convDay( d, m, y );
// cout << birthDay << birthMonth << birthYear;
// Display the result
printf( "%d/%d/%d was %s.\r\n", m, d, y, day_names[ day ]);
system( "pause" ); // wait for user to press a key…
return 0; // normal exit
} // end main()
// function to Calculate the Day of the week given a date
// IN: a day, month, and year
// OUT: a day of the week as a numerical value
// E.g. 0 = Sunday, 1 = Monday, 6 = Saturday
// USES: Calculating the day of the week you were born, of course!
int convDay( int d, int m, int y )
{
int J, K;
if (m < 3)
{
m += 12;
y–;
}
J = y / 100;
K = y % 100;
return (d + 26 * (m + 1) / 10 + K + K/4 + J/4 + 5*J) % 7;
}
return( d+ (int)floor(26*(m+1)/10)+y+(int)floor(y/4)+5)%7;
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
char s[256];
time_t t;
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
if(tmp) {
strftime(s, 255, "%w", tmp);
printf("Day of week: %s\n", s);
} else {
printf("AIEEEEE! No time for time!\n");
}