Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a method / function called daysInMonth ( ) that takes in a month ( as an integer ) and an integer year as parameters

Write a method/function called daysInMonth() that takes in a month (as an integer) and an integer year as parameters and returns the number of days in that month as an integer. For example the call daysInMonth(1,2000) should return 31 as there are 31 days in January(1).
If the user inputs a day in Feburary (2) make sure to account for the possibility of a leap year.
Rules for leap years are:
If a year is divisible by 100, it must also be divisible by 400 to be a leap year. For example, 1600 is a leap year and 1800 is not a leap year.
If a year is not divisible by 100 it must be divisible by 4 to be a leap year. For example, 2024 is a leap year and 2025 is not a leap year.
If the user types in a month that doesn't exist return (-1) as an error message. Do the same for any year that is less than 0.

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions

Question

List the different categories of international employees. page 642

Answered: 1 week ago

Question

Explain the legal environments impact on labor relations. page 590

Answered: 1 week ago