Write a program to determine whether a year entered through the keyboard is a leap year or not. Also determine whether the year is your year of birth, starting your school, start or end of matriculation (or O-levels etc), start or end of Intermediate education (FSC, A-levels, ICOM, ICS etc) or year of starting your education in COMSATS University?
#include <iostream>
bool IsLeap(int year);
int main()
{
int year;
std::cout << "Enter year: ";
std::cin >> year;
if (IsLeap(year)) {
std::cout << "Leap year." << std::endl;
}
else {
std::cout << "Not leap year." << std::endl;
}
int birth_year;
std::cout << "Enter your birth year: ";
std::cin >> birth_year;
if (birth_year == year) {
std::cout << "Entered year is your birth year!" << std::endl;
}
else {
std::cout << "Entered year is not your birth year." << std::endl;
}
int school_year;
std::cout << "Enter year of starting your school: ";
std::cin >> school_year;
if (school_year == year) {
std::cout << "Entered year is a year of starting your school!" << std::endl;
}
else {
std::cout << "Entered year is not a year of starting your school." << std::endl;
}
int start_matriculation_year;
std::cout << "Enter year start of matriculation: ";
std::cin >> start_matriculation_year;
if (start_matriculation_year == year) {
std::cout << "Entered year is a year of start of matriculation!" << std::endl;
}
else {
std::cout << "Entered year is not a year of start of matriculation." << std::endl;
}
int start_intermediate_year;
std::cout << "Enter year of start Intermediate education: ";
std::cin >> start_intermediate_year;
if (start_intermediate_year == year) {
std::cout << "Entered year is a year of start Intermediate education!" << std::endl;
}
else {
std::cout << "Entered year is not a year of start Intermediate education." << std::endl;
}
return 0;
}
bool IsLeap(int year)
{
return (year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0));
}
Comments
Leave a comment