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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
using namespace std;
int main(void)
{
// 1 Introduction - Instructions and Input
int month, day, year;
cout << endl << "Input a date as three numbers separated by spaces (month day year)" << endl;
cout << "\t\t-> "; // this is so it looks neater
cin >> month >> day >> year;
cin.ignore(99,'\n');
// Non Numeric Input
if ( !cin )
{
cin.clear();
cin.ignore(99,'\n');
cout << endl << "Non-numeric input: Program terminating." << endl;
cout << "Press [ENTER] to finish...";
cin.ignore(99,'\n');
return 0;
}
// Date Limits
if ( month < 0 || month > 12 ) // Months should be in the range from 1 (January) to 12 (December)
{
cout << endl << "Date of range: Program terminating." << endl;
cout << "Reason: Months should be in the range from 1 (January) to 12 (December)." << endl;
cout << "Press [ENTER] to finish...";
cin.ignore(99,'\n');
return 0;
}
if ( year < 0 ) // Years should be non-negative.
{
cout << endl << "Input out of range: Program terminating." << endl;
cout << "Reason: Years should be non-negative." << endl;
cout << "Press [ENTER] to finish...";
cin.ignore(99,'\n');
return 0;
}
if ( day < 0 ) // Days also should be non-negative.
{
cout << endl << "Date of range: Program terminating." << endl;
cout << "Reason: Days should be non-negative." << endl;
cout << "Press [ENTER] to finish...";
cin.ignore(99,'\n');
return 0;
}
// January, March, May, July, August, October and December have 31 days.
if ( month = 1,3,5,7,8,10,12 )
{
if ( day > 31 )
{
cout << "Invalid Input, Please check your date and try again.";
cin.ignore(99,'\n');
return 0;
}
}
// April, June, September and November have 30 days
if ( month = 4,6,9,11 )
{
if ( day > 30 )
{
cout << "Invalid Input, Please check your date and try again.";
cin.ignore(99,'\n');
return 0;
}
}
//// Having trouble with February
if ( month = 2 )
{
// Don't know what to put here...
}
// I figure that if none of the IF Statements are True, then the date should be valid
cout << endl << "Date is Valid. :)" << endl;
cout << "Press [ENTER] to finish..." << endl;
// Finish
cin.ignore(99,'\n');
return 0;
}
|