http://forum.codecall.net/c-c/5166-need-...
Any answer to that post?
C++ Help asap?
Well, your code needs to check for leap year, but it doesn't. The year variables u get from the user... yr1 and yr2, run an isleapyear() function on them. Fortunately, it's mostly written for you...borrowing/tweaking from your website:
int isleapyear(int year) // %26lt;-- was "main()
{
int z=1;
while (z%26lt;=year)
{
switch (year % 4)
{
case 0:
if (year % 100 == 0)
{
if (year % 400 == 0)
{
return 1;
}
else
return 0;
}
else
return 1;
break;
case 3:
return 0;
default:
return 0;
break;
}
return 0;
}
....see? I just put "return 0" were it said cout "not a leap year..." and return 1 when it is a leap year... basic true / false deal.
..../// ... //// ....
OK, now use this func to test the year variables in your program:
cout%26lt;%26lt;"Enter Year: ";
cin%26gt;%26gt;yr1;
if(isleapyear(yr1)
{
///is a leap year...handle it...do something...add 1 day...
}
else
{
///not a leap year....cool....
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment