Create a program that will ask the user to input Month Day and Year, the program will output the day and the date.
Sample Output:
Month: 5
Day: 20
Year: 2022
Friday, May, 20, 2022
#include<iostream>
#include<cstring>
using namespace std;
int day_of_week(int d, int m, int y) // by formula
{
int t[] = {6, 2, 1, 4, 6, 2, 4, 0, 3, 5, 1, 3};
if(m<3) y--;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; //returns the number 0-6 (Monday-Sunday)
}
int main(){
const string DAY_NAMES[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
const string MONTH_NAMES[12] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
int day, month, year;
cout<<"Enter the date(1-31): ";
cin>>day;
cout<<"Enter the month(1-12): ";
cin>>month;
cout<<"Enter the year(yyyy): ";
cin>>year;
cout<<DAY_NAMES[ day_of_week(day,month,year) ]<<", "<<MONTH_NAMES[month-1]<<", "<<year<<endl;
return 0;
}
Comments
Leave a comment