How to Calculate Any Day of the Week?
Submitted by oursharingclub on Saturday, September 27, 2014 - 18:08.
Language
Author : Walter
Date : September 27, 2014 Firday
MyBlog : http://learningpen.blogspot.com/
Tool : Dev C++
Language : C++
Function : Calculate any day of the week?
- #include <iostream>
- #include <cmath> // for floor()
- #include <conio.h> // for getch()
- #include <stdlib.h> // for exit()
- #include <windows.h> // for system()
- using std::cout;
- using std::cin;
- //=======================
- void Menu( void );
- int main( void )
- {
- Menu();
- return 0;
- }// End of main function
- //=======================
- void Menu( void )
- {
- int year, month, day;
- int week;
- int century;
- int temp;
- bool flag= false;
- cout<< "\n\n =========== Calculate any day of the week =========== ";
- cout<< "\n\n\t\t Enter year month day: ";
- cin>> year>> month>> day;
- temp= year;
- if( year<= 1582 && month<= 10 && day<= 15 )
- {
- flag= true;
- }
- if( month== 2 || month== 1 )
- {
- year--;
- month= 12+ month;
- }
- century= year/ 100;
- year= year% 100; // The last two digits of the year
- if( flag== false )
- {
- }
- else
- {
- }
- week= ( week% 7+ 7 )% 7;
- year= temp;
- switch( week )
- {
- case 0:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Sunday";
- break;
- }
- case 1:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Monday";
- break;
- }
- case 2:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Tuesday";
- break;
- }
- case 3:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Wednesday";
- break;
- }
- case 4:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Thursday";
- break;
- }
- case 5:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Friday";
- break;
- }
- case 6:
- {
- cout<< "\n\n\t\t ";
- cout<< year<< "-"<< month<< "-"<< day<< ": "<< "Saturday";
- break;
- }
- }
- cout<< "\n\n\t\t Do you want to continue( Y/N ): ";
- char letter;
- cin>>letter;
- {
- Menu();
- }
- else
- {
- cout<< "\n\n\t\t Thank U.";
- }
- }// End of Menu function
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 28 views