Permalink
Cannot retrieve contributors at this time
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?
4003CEM-intro_orig/lab_leap.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38 lines (32 sloc)
934 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |