# C++: Leap Year

• Comp Sci
1. Homework Statement
I just started my C++ courses and here is my question.

2. Homework Equations

3. The Attempt at a Solution
//This program states whether a given year is a leap year or a non-leap year.

#include <iostream.h>
#include <conio.h>

void main ()
{
int year, value;

{
cout << "Please input a year: ";
value = year/4;
if (value==int)
cout << ""<< year << " is a leap year. There are 29 days in Feb " << year <<".";
else
cout << ""<< year << " is a non-leap year. There are 28 days in Feb " << year <<".";
}
cout << "Do you want to continue? Press 'y' if yes or 'n' if no.";
getch();
}

It seems that "if (value==int)" is illegal. Is there any other way I can put th expression statement so that the computer can print out whether a given year is a leap year or not?

Thanks.

Related Engineering and Comp Sci Homework Help News on Phys.org
What you need to do is to check if the variable year is a multiple of 4 and the modulus operator % is perfect for the task, e.g.,
1%4 = 1, 2%4 = 2, 3%4 = 3, 4%4 = 0, 5%4 = 1, ...

What should the conditional expression be for the if-statement now then?

Btw, the rules for checking a leap year is a bit more involved than the above. Look http://en.wikipedia.org/wiki/Leap_year" [Broken] for an insight.

Last edited by a moderator:
Okay, thanks for the help. My instructor just introduced the modulus operator today.