Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called checkLeapYear that takes a single integer argument representing a year and returns true if it is a leap year and false

Write a function called checkLeapYear that takes a single integer argument representing a year and returns true if it is a leap year and false otherwise. This function MUST use a single if statement and Boolean operators.

  • Your function MUST be named checkLeapYear

  • Your function should take one parameter: the year value, as a positive integer

  • Your function only uses if. else cannot be used to solve this problem.

  • Your function should return a boolean value, true or false, according to the leap year definition (see below)

What is a leap year? In general, years divisible by 4 are leap years. For dates after 1582, however, there is a Gregorian correction. Years divisible by 100 are not leap years but years divisible by 400 are. So, for instance, 1900 was not a leap year but 2000 was.

Examples

  • When the argument is equal to 1900, the function should return false;
  • When the argument is equal to 2000, the function should return true.

could someone help me with this problem im confused with where i am going wrong, this is what I have so far

#include using namespace std;

bool checkLeapYear(int yr) { return (yr % 400 == 0 || yr % 100 != 0) && (yr % 4 == 0); if(checkLeapYear(yr)) { cout << yr << " year is a leap year" << endl; } }

int main() { int year = 1600; bool leap = checkLeapYear(1600); int year = 1601; bool leap = checkLeapYear(1601); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

1. Identify three approaches to culture.

Answered: 1 week ago

Question

3. Identify and describe nine cultural value orientations.

Answered: 1 week ago

Question

4. Describe how cultural values influence communication.

Answered: 1 week ago