Answer to Question #324591 in C++ for Secret Agent

Question #324591

 Leap Year Detector

by CodeChum Admin

Let’s try to find out whether a year has 365 or 366 days. To do this, we need to create a leap year detector!


Conditions for a leap year:

1.) year must be divisible by 4 and not divisible by 100

2.) If year is divisible by 100, it must be divisible by 400 for it to be a leap year.


Instructions:

  1. You are provided with the isLeapYear() function which is already declared and defined for you.
  2. Your task is to ask the user for a year and then call the isLeapYear function to check whether the year is a leap year or not.

Input


1. Year to be checked

Output

If a certain year is a leap year, print "<INSERT_YEAR_HERE> is a leap year"

Otherwise, print "<INSERT_YEAR_HERE> is not a leap year"

Enter·year:·2020
2020·is·a·leap·year




1
Expert's answer
2022-04-06T02:27:53-0400




#include<iostream>
#include <string>
using namespace std;




bool isLeapYear(int year){
	if (year % 4 == 0) {
		if (year % 100 == 0) {
			if (year % 400 == 0){
				return true;
			}
		}
		else{
			return true;
		}
	}
	return false;
}
int main()
{
	int year;
	cout<<"Enter year: ";
	cin>>year;
	if(isLeapYear(year)){
		cout<<year<<" is a leap year\n\n";
	}else{
		cout<<year<<" is not a leap year\n\n";
	}
	
	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS