Okay, thank you. It works, Malibor...now I need to use i to recognize when a year(starting with 2020) is a multiple of 4. This is what I have...I'm definitely missing something.
// Gregorian calender; extra leap day occurs in each year that is
// an integer multiple of 4 (except for years evenly divisible by 100, but not by 400)
// https://en.wikipedia.org/wiki/Leap_yearbool is_leap( unsignedint year )
{
if( year%400 == 0 ) returntrue ; // leap year if multiple of 400
elseif( year%100 == 0 ) returnfalse ; // not leap year if multiple of 100, but not multiple of 400
elsereturn ( year%4 == 0 ) ; // else leap year if multiple of 4
}
Thanks, seeplus...this works, but it only seems to spit out leap years. I also need it to print whether there are 365 or 366 days in a user inputted year. My code above accomplished that, it just can't find the leap years like yours can. Is there a way to marry the two?
Nevermind...I figured it out. Thanks for your help!
You didn't say about user inputted year. You only mentioned years 2020 to 3000.
If you want to use it with a given year, then use JLBorges function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
bool is_leap(unsigned year) {
if (year % 400 == 0) returntrue; // leap year if multiple of 400
elseif (year % 100 == 0) returnfalse; // not leap year if multiple of 100, but not multiple of 400
elsereturn (year % 4 == 0); // else leap year if multiple of 4
}
int main() {
unsigned year {};
std::cout << "Enter a year: ";
std::cin >> year;
std::cout << year << " has " << 365 + is_leap(year) << " days\n";
}