I am designing a calender App in c++ that functions upon the year input.
I got a sample code online and i am trying to understand it but i am stuck somewhere.
PLEASE I NEED HELP.
I dont understand from the line that has n=(year_2nd-1)*(365+0.25-0.01+0.0025);
n++;
THIS IS THE CODE FOR THE CALENDER
#include<iostream>
#include<conio.h>
using namespace std;
int showmonth(int month,int year,int n);
int leapyear();
int main()
{
//First part of the application determines wheter the chosen year is a leap year or not.
cout<<"\t\t................................................"<<endl;
cout<<"\t\t\t A CALENDER APPLICATION IN C++"<<endl;
cout<<"\t\t\t PROGRAMMED BY GROUP 1"<<endl;
cout<<"\t\t................................................"<<endl;
cout<<"\n";
leapyear();
cout<<"\n";
cout<<"Now you can enter a year to generate it's calender : ";
char x;//this character is used in repeating the use of the application
x='y';//x would be invoked upon keying y and this y is an input character
while(x=='y')
{
int n,year_2nd;//NB: y has been used as a variable(year) here
//cout<<"Enter any year :- "<<endl;
cin>>year_2nd;
cout<<"\n\n\n\t\tCALENDAR OF THE YEAR "<<year_2nd<<endl;
int showmonth(int month,int y,int n)
{
int d=1,s=1,numberOfdays=31,p;
switch(month)
{
case 1 :cout<<"\nJANUARY\n";
numberOfdays=31;
break;
case 2 :cout<<"\nFEBRUARY\n";
if(((y%4==0)||(y%100==0))||(y%400==0))
numberOfdays=29;
else
numberOfdays=28;
break;
case 3: cout<<"\nMARCH\n";
numberOfdays=31;
break;
case 4: cout<<"\nAPRIL\n";
numberOfdays=30;
break;
case 5:cout<<"\nMAY\n";
numberOfdays=31;
break;
case 6:cout<<"\nJUNE\n";
numberOfdays=30;
break;
case 7:cout<<"\nJULY\n";
numberOfdays=31;
break;
case 8:cout<<"\nAUGUST\n";
numberOfdays=31;
break;
case 9:cout<<"\nSEPTEMBER\n";
numberOfdays=30;
break;
case 10:cout<<"\nOCTOBER\n";
numberOfdays=31;
break;
case 11:cout<<"\nNOVEMBER\n";
numberOfdays=30;
break;
case 12:cout<<"\nDECEMBER\n";
numberOfdays=31;
break;
}
Thanks for the quick reply i am so grateful. Can you please help me understand your code and also how can i integrate it with the one i posted earlier. I am very young in programming.
The code I gave you is just a function. Copy'n'paste it, and call it with the correct argument values.
It is nothing more than a well-known mathematical calculation to determine the day of week the first of a month falls on in the (Modified) Gregorian calendar, according to the reading found at the link I gave you.