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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#include <iostream> // cout, cin
#include <limits> // numeric_limits
using namespace std; // Avoid having to use std:: cout, std:: cin, etc
void drawMenu()
{
// The menu
cout << "******************************************************************" <<endl;
cout << "* choose an entry from 1 to 3. *" <<endl;
cout << "* [1] validate modulus 11 number *" <<endl;
cout << "* [2] validate data *" <<endl;
cout << "* [3] quit *" <<endl;
cout << "******************************************************************" <<endl;
}
int main()
{
//we can simply create a "game" loop for this appication
bool quit= false; // we haven't quitted yet
do
{
// the user choice
int choice;
// print the menu
drawMenu();
// Get the user choice
cin >> choice;
// error check again. include the fast that the number has to be 1-3
while (cin.fail() || choice <1 || choice > 3)
{
cout << endl << "choose a correct entry from 1 to 3 (with numbers)"
<< endl << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
// draw the menu again
drawMenu();
cin >> choice;
}
//check the choice we have received
switch (choice)
{
case1: // if the choice is 1
cout << endl << "Enter an ISNB number: " << endl << endl;
break;
case 2:
int day,dd,mm,yy,num;
char ans;
while (true)
{
cout << "Enter Day: ";
cin >> dd;
cout << "Enter Month: ";
cin >> mm;
cout << "Enter Year: ";
cin >> yy;
if (dd > 0 && mm > 0 && yy > 0)
break;
}
// validation
if (dd, mm, yy)
int month [12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (yy % 4 == 0)
if (mm <= 12 && dd <= "Month" [mm-1])
{
cout << "Date is valid\n";
}
else
cout << "Error: Date is Invalid!\n";
break;
case 3:
quit = true;
break;
default:
break;
}
} while (!quit) ; // keep looping forever, until we quit
//say goodbye
cout << endl <<" shutting down. hope i'll see you soon!" << endl;
return 0;
}
|