Write your question here.
Def: A year is a century year if it is divisible by 100{ex: 100,200}
Def: A year is non- century year if it is not a century year.{ex: 1,2,3}
Def: A year is a leap year if it is a non -century year that is divisible by 4 or a century year divisible by 400 . Nothing else is a leap year.
Write a program that is going to ask the user for the range of years and print out
all leap years in that range 5 to a line ?
I am not able to find how to print 5 numbers to a line
here is my code
//leapyear.cpp
#include <iostream>
using namespace std;
int main ()
{
int n1,n2,counter;
cout << "Please give me a range of year:";
cin >> n1 >> n2;
if(n1<1 || n2<1)
{
cout << "Does not exist";
return 0;
}
for(int c = n1;c<=n2;c++)
{
for(int i = 0 ;i<5;i++)
//leapyear.cpp
#include <iostream>
usingnamespace std;
int main ()
{
int n1,n2,counter = 0;
do
{
cout << "Please give me a range of years:" << endl;
cout << "Starting year : ";
cin >> n1;
cout << "Ending year : ";
cin >> n2;
if(n1<0 || n2<0)
cout << "Leap years did NOT even exist then. Please try again." << endl;
if (n1>n2)
{
cout << "Ending year MUST be greater than the starting year!!" << endl;
n1=0,n2=0;
}
} while (n1<1||n2<1||n1>n2);
for(int year = n1; year<=n2; year++)
{
if((year%100 !=0 && year%4 ==0) || year%400 == 0)
{
counter++;
cout << year << " ";
if (counter == 5)
{
counter = 0;
cout << endl;
}
}
}
cout << endl << endl << "These all are leap years in the given range";
cout << endl;
return 0;
}