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 101 102 103 104 105 106 107 108 109 110
|
#include <iostream> // cout cin
#include <limits> // numeric limits
using namespace std; // avoid using std::cout, std::cin
void drawMenu()
{
// menu
cout <<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
cout <<" Choose an entry from 1 to 3. " << endl;
cout <<" [1] Validate modulus 11 number. " << endl;
cout <<" [2] Validate date. " << endl;
cout <<" [3] Quit " << endl;
cout <<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^" << endl;
}
int main()
{
// we can create a game lopop forr this aplitcatoin
bool quit = false; // we habvent quitter ywt
do
{
// user cohise
int choice;
// print mnu
drawMenu();
// get tghe suere cohihes
cin >> choice;
//error check agani unclude the fact that the number has to be 1-3 while
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');
// drawmyny
drawMenu();
cin >> choice;
}
// check the chouidde we hacve recieved
switch (choice)
{
case 1: // if hte coihed is 1
cout << endl << "Enter an ISBN number: " << endl << endl;
break;
case 2 :
int day,dd,mm,yy,num;
char ans;
label_important:
do{
cout<<"Enter day: \n";
cin>> dd;
}while (dd<1||dd>31);
do{
cout<<"Enter month: \n";
cin>> mm;
}while (mm<1||mm>12);
do{
cout<<"Enter year: \n";
cin>> yy;
}while (yy<1||yy==num);
//validation
switch(mm){
case 1:if (1,3,5,7,8,10,12);
day=31;
break;
case 2: if (4,6,9,11);
day=30;
break;
case 3:
if(((yy%4==0)&&(yy%100!=0)) || (yy%400==0))
day=29;
else
day=28;
}
// the last bit that makes sure if the date is valid or no
if (dd, mm, yy)
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is Valid!"<<endl;
else
cout<<"The Date "<<mm<<'/'<<dd<<'/'<<yy<<" is Invalid"<<endl;
//{
cout<<"Do You want to go back to menu? (y/n) "<<endl;
cin>>ans;
if (ans = 'y') goto label_important;
break;
case 3:
quit = true;
break;
default:
break;
}
}while (!quit); // keep lopoing foiorvfer until wee quiot
// bye
cout << endl << "Shutting down. Bye :) " << endl << endl;
return 0;
}
|