Answer to Question #251470 in C++ for adas

Question #251470

The program should behave as follows. 1. The program reads an integer and stores it in a variable year of type int. 2. If the number is not between 2000 and 2100 (with both ends included), the program should warn the user and stop (this just means that no further statements are executed by the program). Otherwise, it should proceed as follows. 3. Declare a variable leapYear of type bool which will be true if the number stored in year corresponds to a leap year, and false otherwise. 4. Use a loop to compute the value of leapYear according to the year introduced by the user. Hint: keep subtracting 4 from the value stored in year until reaching a certain condition. 5. Use year and leapYear to output the following to the screen: - if year is not a leap year, for example 2010, print The year is 2010 and it's not a leap year. - if year is a leap year, for example 2020, print The year is 2020 and it's a leap year. 


1
Expert's answer
2021-10-14T20:06:59-0400
#include<iostream>
using namespace std;
int main(){
	cout<<"Enter year: \n";
	int year;
	cin>>year;
	if(year>=2000 && year<=2100){
		exit(0);
	}
	else{
	bool leapYear ;
	 if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
	 	leapYear = true;
	 	cout<<"The year is "<<year<<" and it's a leap year\n";
	 }
	 else{
	 	leapYear = false;
	cout<<"The year is "<<year<<" and it's not a leap year\n";
	 }
	
	}
}

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