1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <iostream>
#include <string>
using namespace std;
bool isValidRange( int n, int mn, int mx ) { return n >= mn && n <= mx; }
int main()
{
const string months[13] = { "", "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
unsigned int month, day, year;
char dash;
cout << "Please enter your birthdate in the format mm-dd-yyyy: "; // grrr, American order
cin >> month >> dash >> day >> dash >> year;
if ( isValidRange( month, 1, 12 ) &&
isValidRange( day , 1, 31 ) &&
isValidRange( year , 1800, 2019 ) )
{
cout << "Your birthday is " << months[month] << " " << day << ", " << year << "\n";
}
else
{
cout << "Invalid Date!";
}
}
|