Thursday, March 12, 2015

Day Checker in C++

In this article I would like to share with you a sample program in C++ that I wrote that will determine or check what is the day in a given date by our user using C++ as programming language. What our program will do is very simple it will ask the user to enter the month, day and year and then our program will determine what day will fall in the given date by our user. I also added a function that will ask the user if the user want to continue using the program or not. I hope you will find my work useful in your programming assignments and projects.

If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.

People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360




Program Listing

#include <iostream>
#include <ctype.h>

using namespace std;

char *check_day(int day){
   switch(day){
      case 0 :return("SUNDAY");
      case 1 :return("MONDAY");
      case 2 :return("TUESDAY");
      case 3 :return("WEDNESDAY");
      case 4 :return("THURSDAY");
      case 5 :return("FRIDAY");
      case 6 :return("SATURDAY");
      default:return("Sorry Invalid Value Please Try Again...");
   }
}

int check_day(int month,int day,int year){
    static int t2[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
    year-= month < 3;
    return (year + year/4 - year/100 + year/400 + t2[month-1] + day) % 7;
}

int main(){
    int month=0, day=0, year=0;
    char reply;
do {
    cout << "\n";
    cout << "\t=============================";
    cout << "\n";
    cout << "\t=======[ DAY CHECKER ]=======";
    cout << "\n";
    cout << "\t=============================";
    cout << "\n\n";
    cout << "\tPLEASE ENTER MONTH DAY AND YEAR :=> ";
    cin >> month >> day >> year;
    cout << "\n\n";
    cout << "\t Day in a given date is  " << check_day(check_day(month,day,year));
    cout << "\n\n";
    cout << "\t Do you want to continue y/n :=> ";
    cin >> reply;
   } while (toupper(reply)=='Y');
    cout << "\n\n";
    cout << "\t THANK YOU FOR USING THIS PROGRAM.";
    cout << "\n\n";
}


No comments:

Post a Comment