Hi
I have a bool function that should find whether a year was a leap year or not. But the function is not returning the correct years as a leap year.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool is_leapyear(int year);
int main () {
int a = 2000, b = 2004, c = 2005, d = 2007;
if (is_leapyear(a))
{
cout << a << " is a LEAP year" << endl;
}
else
cout << a << " is NOT a LEAP year" << endl;
if (is_leapyear(b))
{
cout << b << " is a LEAP year" << endl;
}
else
cout << b << " is NOT a LEAP year" << endl;
if (is_leapyear(c))
{
cout << c << " is a LEAP year" << endl;
}
else
cout << c << " is NOT a LEAP year" << endl;
if (is_leapyear(d))
{
cout << d << " is a LEAP year" << endl;
}
else
cout << d << " is NOT a LEAP year" << endl;
return 0;
}
bool is_leapyear(int year)
{
bool leap_yr = false;
if (((year % 4) == 0) && ((year % 100) != 0) || year % 16 == 0)
{
leap_yr = true;
}
else
leap_yr = false;
}
output for program is:
2000 is NOT a LEAP year
2004 is a LEAP year
2005 is a LEAP year
2007 is a LEAP year