
// Please enter your birthday in this
// format(including spaces):
// DD MM YYYY
// 22 01 1997
#include <iostream>
using namespace std;
int main(void)
{
int DD = 32, MM = 13, YYYY = -1, NYYYY, NMM, IDAY, day, flag = 0;
string month[] = {βJanuaryβ,βFebruaryβ,βMarchβ,βAprilβ,βMayβ,βJuneβ,βJulyβ,
βAugustβ,βSeptemberβ,βOctoberβ,βNovemberβ,βDecemberβ};
cin >> DD;
cin >> MM;
cin >> YYYY;
//Error Message: User has given no input
if(DD == 32 && MM == 13 && YYYY == -1)
{
cout << β Please enter your birthday in this β << endl;
cout << β format(including spaces): β << endl;
cout << β DD MM YYYY β << endl;
cout << β 22 01 1997 β << endl;
return -1;
}
if(DD <= 0)
{
//Error Message: User has given invalid input for βDaysβ & βMonthsβ fields
if(MM <= 0)
{
cout << β We donβt have negative or null days and months. β << endl;
cout << β Try again! β << endl;
return -1;
}
//Error Message: User has given invalid input for βDaysβ field
cout << β We donβt have negative or null days. β << endl;
cout << β Try again! β << endl;
return -1;
}
if(MM <= 0)
{
//Error Message: User has given invalid input for βMonthsβ field
cout << β We donβt have negative or null months. β << endl;
cout << β Try again! β << endl;
return -1;
}
if(DD > 31 || MM > 12 || YYYY <= 0)
{
if(DD > 31 && MM > 12)
{
//Error Message: User has given invalid input for βDaysβ, βMonthsβ & βYearsβ fields
if(YYYY <= 0)
{
cout << β We have 12 months, the days of a month are up to 31 β << endl;
cout << β and a year should be a positive number. β << endl;
cout << β Try again! β << endl;
}
//Error Message: User has given invalid input for βDaysβ & βMonthsβ fields
else
{
cout << β We have 12 months and β << endl;
cout << β the days of a month are up to 31. β << endl;
cout << β Try again! β << endl;
}
}
else if(DD > 31 && MM <= 12)
{
//Error Message: User has given invalid input for βDaysβ & βYearsβ fields
if(YYYY <= 0)
{
cout << β The days of a month are up to 31 and β << endl;
cout << β a year should be a positive number. β << endl;
cout << β Try again! β << endl;
}
//Error Message: User has given invalid input for βDaysβ field
else
{
cout << β The days of a month are up to 31. β << endl;
cout << β Try again! β << endl;
}
}
else if(DD <= 31 && MM > 12)
{
//Error Message: User has given invalid input for βMonthsβ & βYearsβ fields
if(YYYY <= 0)
{
cout << β We have 12 months and β << endl;
cout << β a year should be a positive number. β << endl;
cout << β Try again! β << endl;
}
//Error Message: User has given invalid input for βMonthsβ field
else
{
cout << β We have 12 months. β << endl;
cout << β Try again! β << endl;
}
}
//Error Message: User has given invalid input for βYearsβ field
else if(DD <= 31 && MM <= 12 && YYYY <= 0)
{
cout << β A year should be a positive number. β << endl;
cout << β Try again! β << endl;
}
return -1;
}
switch(MM)
{
case 2:
if((YYYY % 400) == 0 || ((YYYY % 4) == 0 && (YYYY % 100) != 0))
{
//Error Message: User has requested an invalid day for the month βFebruaryβ
// and the requested βYearβ is a leap year.
if(DD > 29)
{
cout << β The year β << YYYY << β is a leap year. β << endl;
cout << β So, February has up to 29 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
}
else
{
//Error Message: User has requested an invalid day for the month βFebruaryβ
// and the requested βYearβ is not a leap year.
if(DD > 28)
{
cout << β The year β << YYYY << β isnβt a leap year. β << endl;
cout << β So, February has up to 28 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
}
break;
case 4:
//Error Message: User has requested an invalid day for the month βAprilβ
if(DD > 30)
{
cout << β April has up to 30 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
break;
case 6:
//Error Message: User has requested an invalid day for the month βJuneβ
if(DD > 30)
{
cout << β June has up to 30 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
break;
case 9:
//Error Message: User has requested an invalid day for the month βSeptemberβ
if(DD > 30)
{
cout << β September has up to 30 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
break;
case 11:
//Error Message: User has requested an invalid day for the month βNovemberβ
if(DD > 30)
{
cout << β November has up to 30 days. β << endl;
cout << β Try again! β << endl;
return -1;
}
break;
}
if(MM <= 2)
{
NYYYY = YYYY β 1;
NMM = 0;
}
else
{
NYYYY = YYYY;
NMM = (4 * MM + 23) / 10;
}
//Calculating the day
IDAY = 365 * YYYY + DD + 31 * (MM β 1) β NMM + (NYYYY / 4) β ((3 * ((NYYYY / 100) + 1) / 4));
day = IDAY % 7;
//This βflagβ is used for displaying the right ending after the numbers
if(DD != 11 && DD != 12 && DD != 13)
flag = DD % 10;
switch(day)
{
case 0:
cout << β You were born on Saturday, β;
break;
case 1:
cout << β You were born on Sunday, β;
break;
case 2:
cout << β You were born on Monday, β;
break;
case 3:
cout << β You were born on Tuesday, β;
break;
case 4:
cout << β You were born on Wednesday, β;
break;
case 5:
cout << β You were born on Thursday, β;
break;
case 6:
cout << β You were born on Friday, β;
break;
}
if(flag == 1){
cout << DD << βst of β;
}
else if(flag == 2){
cout << DD << βnd of β;
}
else if(flag == 3){
cout << DD << βrd of β;
}
else{
cout << DD << βth of β;
}
cout << month[MM-1] << β of β << YYYY << β!β << endl;
cout << β\n And if you liked it, β << endl;
cout << β donβt forget to give a (+1) like! β << endl;
cout << β Thank you! β << endl;
return 0;
}
Topics Covered :
c++(programming language)
c++programming language tutorial
c programming course
proramming journey
c++programming
c programming for beginners
programiz learn programming
language basics
learn c programming
Thanks for reading this blog. Hope you get satisfied with the blog and definitely this blog must have valued your time and effort of reading.
Take a time to connect our other digital creations such as Instagram , Facebook and Youtube.
Social Media Links of Tech DCode :
YouTube : https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
Instagram : https://www.instagram.com/thetechdcode/
Facebook Page : https://www.facebook.com/thetechdcode
Twitter : https://twitter.com/thetechdcode
Telegram Channel : https://t.me/thetechdcode
Tech DCode Linktree : https://linktr.ee/thetechdcode
My Personal Handles : https://linktr.ee/virtualshivamin
Social Media Links of SHIVAM SINGH (OWNER) :
Instagram : https://www.instagram.com/virtualshivamin/
Facebook Page : https://www.facebook.com/virtualshivamin/
Twitter : https://twitter.com/virtualshivamin/
Personal Linktree : https://linktr.ee/virtualshivamin