You want a function like isLeapYear() to return a bool, not an int, since all you want is a true or false check. Note that I'm using an int as a bool. Any nonzero int will return true when used as a bool, and 0 will return false. That could have been written as
which might be clearer for you to visualize what's going on.
If isLeapYear() returns true, add 366 instead of 365 to your variable. I'm assuming you want a function that returns the number of days passed since 1753, for some reason. You could write it like this:
1 2 3 4 5 6 7 8 9 10 11
int daysSince1753(int year)
{
int days = 0;
for(int i = year; i > 1753; --i)
{
days += isLeapYear(i) ? 366 : 365;
}
return days;
}
Of course, you should check for errors (an argument that is < 1753) and it would be better to place your constant in a constint.
I thought it would be clear, sorry: I renamed your daysYear() function to daysSince1753() because it seemed more fitting.
Anyway, take a good look at your program above and think for a while about what it does. You should be able to explain what each line of code does. When in doubt, go back to your book or this site's tutorial until you understand what you're doing. Your code never calls daysSince1753(), for instance, and it adds a bool to holderV. A bool will be converted to 0 or 1 if used as you do. Basically, your code is simply adding 1 to holderV every time isLeapYear() returns true. You're probably ending up with the number of leap years since 1753. Also, the expression on line 27 (-1) isn't really doing anything, although it is legal.
#include <iostream>
using std::cout;
bool IsLeapYear( int );
int main()
{
for(int i = 2008; i < 2015; i++){
if (IsLeapYear(i)){
cout << i << " is Leap Year!!!\n";
}
else{
cout << "I guess " << i << " is not leap year...\n";
}
}
return 0;
}
bool IsLeapYear( int year ){
return (year % 4 == 0)?true:false;
}
2008 is Leap Year!!!
I guess 2009 is not leap year...
I guess 2010 is not leap year...
I guess 2011 is not leap year...
2012 is Leap Year!!!
I guess 2013 is not leap year...
I guess 2014 is not leap year...