Problem :
----------------------------------------------------------------------------
write a program that reads a year and determin and print whtether itis leap year or not
the screen dialogue should appear as follows :
) enter a year :1999 )
( this is not a leap year )
) enter a year :2000)
) this is a leap year )
-----------------------------------------------------------------------------
its easy but the problem is that I do not know what is the condition of the if !!
Here is my program:
--------------------------------------
#include <iostream>
using namespace std;
int main ()
{
int year;
cout<<"Enter a year: ";
cin>>year;
if (year ????????)
cout<<"this is a leap year\n";
else
cout<<"this is not a leap year\n"
return 0;
}
--------------
I put ???????? in the if condition because i do not know what i should write here
help please
am given a hint: use the modulus operator.
but am lost .. what should i do ??
@General,
Yes, that's how you use the modulo operator; but according to wikipedia (thanks, Bazzy) a leap year really occurs when the year is divisble by four, but not 100 (unless it's divisible by 400). Modify your code accordingly. Good luck.
that's still not right. You have to test more than one condition. A year is a leap year if it's divisible by 4 and not divisible by 100 except when it's divisible by 400.
#include <iostream>
using namespace std;
int main ()
{
int year;
cout<<"Enter a year: ";
cin>>year;
if (year%4==0 && year%100!=0 || year%400==0)
cout<<"this is a leap year\n";
else
cout<<"this is not a leap year\n";
return 0;
}
here the conditions for the leap year is satisfied...