I just started reading c++ tutorial here while also learning from the book.
So here is my problem.
1 2 3 4 5
if ((yearBorn % 4) == 0) // 14 % 4 = 2
{
cout << "\nYou were born in a Leap Year--cool!\n";
}
CURRENTYEAR 2014 - yearBorn 2000 is 14 then 14 % 4 is 2
so that means so yearBorn is not equal to 0 but it keeps printing
"You were born..." Why i'm getting this?
Thank you.
#include <iostream>
#define CURRENTYEAR 2014
usingnamespace std;
int main()
{
int yearBorn, age;
cout <<"What year were you born?\n";
cin >> yearBorn;
if (yearBorn > CURRENTYEAR)
{
cout << "Really? You haven't been born yet?\n";
cout << "Want to try again with a different year?\n";
cout << "What year were you born?\n";
cin >> yearBorn;
}
age = CURRENTYEAR - yearBorn;
cout <<"\nSo this year you will turn " << age << " on your birthday!\n";
if ((yearBorn % 4) == 0)
{
cout << "\nYou were born in a Leap Year--cool!\n";
}
return 0;
}
#include <iostream>
#define CURRENTYEAR 2014
usingnamespace std;
int main()
{
int yearBorn, age;
do
{
cout << "What year were you born?\n";
cin >> yearBorn;
}while (yearBorn > CURRENTYEAR);
age = CURRENTYEAR - yearBorn;
cout << "\nSo this year you will turn " << age << " on your birthday!\n";
if ((yearBorn % 4 == 0) && !(yearBorn % 100 == 0) || (yearBorn % 400 == 0))
cout << "\nYou were born in a Leap Year--cool!\n";
return 0;
}