Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "lab_leap.h"
#include "input.h"
#include <iostream>
int main()
{
int year;
/* Get the user input and deal with invalid values
So this is a better approach than just going
std::cin >> year;
As it its behaviour will be predicatable if the
user enters something that is not an integer.
I have written the input() function that we are
using here, if you want to see how it works, look
in the input.h file. */
try
{
std::cout << "Enter the year you want to check: ";
year = input<int>();
}
catch( std::runtime_error &e )
{
std::cerr << e.what() << std::endl;
return 1;
}
// is it a leap year?
const bool leap = is_leap( year );
// print leap year message
std::cout << year << " is";
if( !leap ) std::cout << "n't";
std::cout << " a leap year" << std::endl;
return 0;
}