The program should ask the user to enter a number as a year. The program then te
ID: 3544434 • Letter: T
Question
The program should ask the user to enter a number as a year. The program then tests whether the input year is a leap year or not. Finally, it displays a message to indicate a leap year or not. To determine if a year is a leap year or not:
A year is leap if it is divisible by 400 (example 1600).
A year is leap if it is divisible by 4 but not divisible by 100 (example 2012).
A year is Not leap if it is divisible 4 and by 100 (example 1700).
A year is Not leap if it is not divisible by 4 (example 2013).
Your program should display an error message when user enters a 0 or negative number.
Example of program run:
Please Enter a year: 2013
Year 2013 is not a leap year
Explanation / Answer
#include<iostream>
using namespace std;
void isleapyear (int y)
{
if((y%400==0)||((y%4==0)&&(y%100!=0)))
cout<<"Leap year"<<endl;
else
cout<<"Not a Leap year";
}
int main()
{
int y;
cout<<"enter the year: ";
cin >> y;
if(y<=0)
cout<<"wrong input";
else
isleapyear(y);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.