I wrote this code to determine whether or not an inputted year is a leap year. Meaning, those divisible by 4 and 400 are leap years, and by 100 or something else are not.
But, my program always returns true for the boolean value, so that output will believe every year is a leap year.
Here's my code so far:
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
bool leap_year(int year);
int main()
{
int year;
bool leap_year(int year);
cout << "Please input the year in question: ";
cin >> year;
if (leap_year == false)
{
cout << "The year is not a leap year. ";
}
else
{
cout << "The year is a leap year. ";
}
return 0;
}
bool leap_year(int year)
{
if (year % 4 == 0)
{
bool leap_year = true;
}
else if (year % 400 == 0)
{
bool leap_year = true;
}
else if (year % 100 == 0)
{
bool leap_year = false;
}
else
{
bool leap_year = false;
}
if (bool leap_year = false)
{
return false;
}
else
{
return true;
}
}