/*|||||||||||||||||||||||||||||||||||||||||*\
*this program inputs a value and checks *
*to see if the input number is divisible *
*by 4, 100 and makes sure its not divisible *
*by 400 *
*********************************************
* *finds what year a leep year is* *
*********************************************
* 0 = false, 1 = true *
\*|||||||||||||||||||||||||||||||||||||||||*/
#include<iostream>
usingnamespace std;
int main()
{
int year;
int Divisible_4 = 1;
int Divisible_100 = 1;
int Divisible_400 = 0;
cout << " Welcome to the Leap Year Finder " << endl;
cout << " Type in the year: ";
cin >> year;
// checkes if years is divisible by 4
if(year == year - (4 * year / 4))
{
Divisible_4 = 1;
}
else
{
Divisible_4 = 0;
}
// checkes if years is divisible by 100
if(year == year - (100 * year/ 100))
{
Divisible_100 = 1;
}
else
{
Divisible_100 = 0;
}
// checkes if years is not divisible by 400
if(year == year - (400 * year / 400))
{
Divisible_400 = 0;
}
else
{
Divisible_400 = 1;
}
if(Divisible_4 == 1 && Divisible_100 == 1 && Divisible_400 == 0)
{
cout << " Yes this is a leap year " << endl;
}
else
{
cout << " No this is not a leap year " << endl;
}
system("PAUSE");
return 0;
}
I would like to know if it is my math or the if statments that stop it from working properly
(i have already tryed difining the varibles
it dosent work it still returns that it is not a leep year
i have located were the problem is but not what
where:
1 2 3 4 5 6 7 8
if(Divisible_4 == 1 && Divisible_100 == 1 && Divisible_400 == 0)
{
cout << " Yes this is a leap year " << endl;
}
else
{
cout << " No this is not a leap year " << endl;
}
I looked up the formula for a leap year and I think you're a little off with your formula. Any year that is divisible by 4 and not divisible by 100 is a leap year. Any year that is divisible by 100 and divisible by 400 is a leap year.
I made the requisite changes to your program and it worked (only tried a few years though).
int main()
{
int year;
int Divisible_4 = 1;
int Divisible_100 = 1;
int Divisible_400 = 0;
cout << " Welcome to the Leap Year Finder " << endl;
cout << " Type in the year: ";
cin >> year;
// checkes if years is divisible by 4
if(year % 4 == 0)
{
Divisible_4 = 1;
}
else
{
Divisible_4 = 0;
}
// checkes if years is divisible by 100
if(year % 100 == 0)
{
Divisible_100 = 1;
}
else
{
Divisible_100 = 0;
}
// checkes if years is not divisible by 400
if(year % 400 == 0)
{
Divisible_400 = 1;
}
else
{
Divisible_400 = 0;
}
if((Divisible_4 == 1 && Divisible_100 == 0) || (Divisible_100 == 1 && Divisible_400 == 1))
{
cout << " Yes this is a leap year " << endl;
}
else
{
cout << " No this is not a leap year " << endl;
}
system("PAUSE");
return 0;
}
Sorry I didn't read that rule and I didn't know it.
It leaved me very perplexed but it's effectively right
I leaved 28 years before i have finally known that not all years divisible by 4 are leep year
:( sob!