Answer to Question #277200 in C++ for Roe

Question #277200

Write c++ code that



(1) Please enter the value of a year through the keyboard.


(2) Please program to determine whether the entered year is a leap year.


(3) The conditions for a leap year are: divisible by 4 but not divisible by 100; or divisible by 400.


(4)run test the code in main

1
Expert's answer
2021-12-08T03:07:00-0500
#include <iostream>
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 a year: ";
	cin >> year;


	if(isLeapYear(year)){
		cout << year << " is a leap year.";
	}else{
		cout << year << " is NOT a leap year.";
	}
	
	cin >> year;
	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