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
|
#include <iostream>
using namespace std;
int main()
{
int m, d, y;
int age;
const int CY = 2018; //By convention, constants are often all caps
//age = (cy - y);
//Get month
do
{
cout << "\n\nEnter month in numerical: ";
cin >> m;
if (m < 1 || m > 12)
cout << "You have entered invalid value!";
}
while (m < 1 || m > 12);
//Get day
do
{
cout << "\n\nEnter day in numerical: ";
cin >> d;
if (d < 1 || d > 31)
cout << "You have entered invalid value!";
}
while (d < 1 || d > 31);
//Get year
cout << "\n\nEnter year in numerical: ";
cin >> y;
//Calculate age
age = ( CY - y);
//Display
switch (m)
{
case 1:
cout << "\nJanuary " << d << ", "<< y << " is now " << age << endl;
break;
case 2:
cout << "\nFebruary " << d << ", "<< y << " is now " << age << endl;
break;
case 3:
cout << "\nMarch " << d << ", "<< y << " is now " << age << endl;
break;
case 4:
cout << "\nApril " << d << ", "<< y << " is now " << age << endl;
break;
case 5:
cout << "\nMay " << d << ", " << y << " is now " << age << endl;
break;
case 6:
cout << "\nJune " << d << ", " << y << " is now " << age << endl;
break;
case 7:
cout << "\nJuly " << d << ", " << y << " is now " << age << endl;
break;
case 8:
cout << "\nAugust " << d << ", " << y << " is now " << age << endl;
break;
case 9:
cout << "\nSeptember " << d << ", " << y << " is now " << age << endl;
break;
case 10:
cout << "\nOctober " << d << ", " << y << " is now " << age << endl;
break;
case 11:
cout << "\nNovember " << d << ", " << y << " is now " << age << endl;
break;
case 12:
cout << "\nDecember " << d << ", " << y << " is now " << age << endl;
break;
}
system("PAUSE");
return 0;
}
|