Computers and Technology

A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4
2) If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400
Some example leap years are 1600, 1712, and 2016.
Write a program that takes in a year and determines whether that year is a leap year.
Ex: If the input is:
1712
the output is:
1712 is a leap year.
Ex: If the input is:
1913
the output is:
1913 is not a leap year.
Your program must define and call the following function. The function should return true if the input year is a leap year and false otherwise.
bool IsLeapYear(int userYear)
Note: This is a lab from a previous chapter that now requires the use of a function.
#include
using namespace std;
bool IsLeapYear(int userYear) {
int userYear;
bool isLeapYear;
}
if (userYear % 100 == 0) {
if (userYear % 400 == 0) {
isLeapYear = true;
cout << userYear << " is a leap year." << endl;
}
else {
isLeapYear = false;
cout << userYear << " is not a leap year." << endl;
}
}
else {
if (userYear % 4 == 0) {
isLeapYear = true;
cout << userYear << " is a leap year." << endl;
}
else {
isLeapYear = false;
cout << userYear << " is not a leap year." << endl;
}
}
return isLeapYear
}
int main () {
int userYear;
cin >> userYear;
if (isLeapYear(userYear) == true) {
cout << userYear << " is a leap year" << endl;
}
else {
cout << userYear << " is not a leap year" << endl;
}
return 0
}

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:30, riah133
Creating "smart interfaces" in all sectors of industry, government, and the public arena is one of the fastest growing hct areas. these interfaces model, interpret, and analyze such human characteristics as speech, gesture, and vision. the field of biometrics, in which humans authenticate themselves to machines, is an area of considerable interest to hct practitioners. fingerprint scans are one of the most frequently used biometric options, and this article, biometric student identification: practical solutions for accountability & security in schools, makes a case for the implementation of fingerprint scans in schools. critique the article, and answer the following questions: according to the author, what are the main benefits of adopting fingerprint scans in schools for student identification? according to the author, what are the main drawbacks of adopting fingerprint scans in schools for student identification? do you agree with the author's assessment of the pl
Answers: 2
image
Computers and Technology, 23.06.2019 02:30, paolaviviana
Experimental data that is expressed using numbers is said to be
Answers: 1
image
Computers and Technology, 24.06.2019 08:30, trashellyoung
Why might you choose to create a functional resume
Answers: 1
image
Computers and Technology, 24.06.2019 12:30, nomood
Select all that apply. what two keys listed below should you use to enter data in an excel worksheet? tab backspace enter right arrow
Answers: 2
Do you know the correct answer?
A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to...

Questions in other subjects:

Konu
Mathematics, 14.04.2021 01:00
Konu
English, 14.04.2021 01:00
Konu
Mathematics, 14.04.2021 01:00