please tell me what i did wrong in this program... the leapyear is not working. it only shows feb 28 in every year.
Thanks alot.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
bool leaptest;
void calendar(int startday, int month1, int year1);
int main()
{
int startday, month, year;


cout <<"Enter a start day>: ";
cin >>startday;


cout <<"Enter month>: ";
cin >>month;


cout <<"Enter year>: ";
cin >>year;


calendar(startday,month,year);


int stop;cin >>stop;
return 0;
}


void calendar(int startday, int month1, int year1)
{
void setweekdays(int &startday2,int month2,int year2);
int monthdays (int mthDays, int year3);
void nameofmonth (int month);
int leapyear (int year2);
int x=0,days;


setweekdays(startday, month1, year1);
cout <<"\t\t";


nameofmonth (month1);
cout <<" "<<year1<<endl;


cout <<"Sun\tMon\tTue\tWed\tThr\tFri\tSat\n";


for(int i=0;i<=startday-1;i++)
{
cout<<"\t ";
x++;
}
days = monthdays(month1,year1);
for(int i=1; i<=days; i++)
{
cout << i <<"\t";
x++;
if(x==7)
{
cout<<endl;
x=0;
}
}
cout <<"\n\n";
}


int leapyear(int year3)
{
if (year3 % 4 == 0){
if (year3 % 100 == 0){
if (year3 % 400 == 0)
leaptest = true;
else leaptest = false;
}
else leaptest = true;
}
else leaptest = false;
return leaptest;
}


void nameofmonth (int month)
{
if ((month < 1) || (month > 12)){cout <<"Incorrect input !";}
else if (month==1){cout <<"January";}
else if (month==2){cout <<"Febuary";}
else if (month==3){cout <<"March";}
else if (month==4){cout <<"April";}
else if (month==5){cout <<"May";}
else if (month==6){cout <<"June";}
else if (month==7){cout <<"July";}
else if (month==8){cout <<"August";}
else if (month==9){cout <<"September";}
else if (month==10){cout <<"October";}
else if (month==11){cout <<"November";}
else if (month==12){cout <<"December";}


}
int monthdays (int mthDays, int year3)
{
switch (mthDays)
{   case 1:mthDays=31;break;
case 2:mthDays=28;break;
case 3:mthDays=31;break;
case 4:mthDays=30;break;
case 5:mthDays=31;break;
case 6:mthDays=30;break;
case 7:mthDays=31;break;
case 8:mthDays=31;break;
case 9:mthDays=30;break;
case 10:mthDays=31;break;
case 11:mthDays=30;break;
case 12:mthDays=31;break;
}
if (mthDays == 2){
if (leaptest == true)
mthDays = 28;
else
mthDays = 29;
}
return mthDays;
}
void setweekdays(int &startday2,int month2,int year2)
{
int i,sum;
sum=startday2;
for(i=1;i<month2;i++)
sum=sum+monthdays(i,year2);
sum=sum%7;
if(i>1)
{
if(sum==0) startday2=6;
else startday2=sum;
}
}
Member Avatar for iamthwee

>it only shows feb 28 in every year.


Hint is it correct?

int leapyear ( int year3 )
{
  if ( year3 % 4 == 0 )
  {
    if ( year3 % 100 == 0 )
    {
      if ( year3 % 400 == 0 )
        leaptest = true;
      else leaptest = false;
    }
    else leaptest = true;
  }
  else leaptest = false;
  return leaptest;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.