Problems with Leap Year check

Trying to get my leapyear checker to work, but I'm finding it's not working regardless how I move things about. Any tips?

In member function `void DayOfYear::check_date()':
99 invalid use of member (did you forget the `&' ?)
99 At global scope:
216 prototype for `int DayOfYear::checkleapyr(int)' does not match any in class `DayOfYear'
23 int DayOfYear::checkleapyr()

#include <iostream>
using namespace std;

class DayOfYear
{
public:
void input( );
void output( );

void set(int new_month,int new_day,int new_year);
//Precondition: new_month and new_day form a possible date.
//Postcondition: The date is reset according to the arguments.

int get_month( );
//Returns the month, 1 for January, 2 for February, etc.

int get_day( );
//Returns the day of the month.
int get_year( );
//Return the year
int checkleapyr( );

private:
void check_date( );
int month;
int day;
int year;
};

int main( )
{
DayOfYear today, bach_birthday;
cout << "Enter today's date:\n";
today.input( );
cout << "Today's date is ";
today.output( );

bach_birthday.set(3, 21, 1685);
cout << "J. S. Bach's birthday is ";
bach_birthday.output( );

if (today.get_month( ) == bach_birthday.get_month( ) && today.get_day( ) == bach_birthday.get_day( ))
cout << "Happy Birthday Johann Sebastian!\n";
else
cout << "Happy Unbirthday Johann Sebastian!\n";
system("pause");
return 0;
}
//Uses iostream:
void DayOfYear::input( )
{
cout << "Enter the month as a number: ";
cin >> month;
cout << "Enter the day of the month: ";
cin >> day;
cout << "Enter the year: ";
cin >> year;
checkleapyr( );
check_date( );
}
//Uses private member functions to accept the month and day of the month.

void DayOfYear::output( )
{
cout << "Month = " << month << " "
<< "Day = " << day << " "
<< "Year = " << year << " " << endl;
}

void DayOfYear::set(int new_month, int new_day, int new_year)
{
month = new_month;
day = new_day;
year = new_year;
check_date( );
}

void DayOfYear::check_date( )
{
/*if ((month < 1) || (month > 12) || (day < 1) || (day >31) || (year < 1685) || (year > 9999))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
*/switch(month)
{
case 1:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 2:
if ( (day < 1) || (day > 28) && (checkleapyr = 1) )
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
else
{
if ( (day < 1) || (day > 29) )
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
}
break;
case 3:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 4:
if ( (day < 1) || (day > 30))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 5:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 6:
if ( (day < 1) || (day > 30))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 7:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 8:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 9:
if ( (day < 1) || (day > 30))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 10:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 11:
if ( (day < 1) || (day > 30))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
case 12:
if ( (day < 1) || (day > 31))
{
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
break;
default:
cout << "Illegal date. Aborting program.\n";
system("pause");
exit(1);
}
}

int DayOfYear::get_month( )
{
return month;
}

int DayOfYear::get_day( )
{
return day;
}
int DayOfYear::get_year( )
{
return year;
}
int DayOfYear::checkleapyr(int checkleapyr)
{
//checks for leap year
switch (year % 4)
{
case 0:
{
if (year % 100 == 0)
{
if (year % 400 == 0)
{
int checkleapyr = 0;
}
else
{
int checkleapyr = 1;
}
}
else
int checkleapyr = 0;
break;
}
case 3:
{
int checkleapyr = 1;
break;
}
default:
int checkleapyr = 1;
break;
}
system("pause");
return 0;
}
216 prototype for `int DayOfYear::checkleapyr(int)' does not match any in class `DayOfYear'


In the class you declare checkleapyr as taking no parameters.
int checkleapyr( );

When you define checkleapyr you say it takes an int as a parameter.
int DayOfYear::checkleapyr(int checkleapyr)

This
if ( (day < 1) || (day > 28) && (checkleapyr = 1) )
should be
if ( (day < 1) || (day > 28) && (checkleapyr() == 1) )
Last edited on
Sorry im on my phone so hard to type what I want. In short, your checkleapyr always returns 0. If you intend to return then just return where you are setting the variable that you passed in. also, since you pass by value, assigning checkleapyr inside the function is not reflected ouit also looks like your call to the function checkleapyr is incorrect, look at your call site.
Topic archived. No new replies allowed.