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
|
#include <iostream>
#include <string>
using namespace std;
int main ()
{
// Declarations of variables and arrays with sizes.
int num,
leapYear,
year;
int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
string month[12] = {"Jan", "Feb", "March", "Apr", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"};
string choice;
do
{
cout << "Please enter a numerical month number (1-12) ";
cin >> num;
if(num > 0 && num <= 12)
{
// Nested decision statements.
if (num == 2)
{
// Decrement by 1.
num--;
// Prompt
cout << "Please enter a year ";
cin >> year;
// Determines the year entered is a leap year by modular division.
leapYear = year % 4;
// Determines how many days is in the month and outputs.
if (leapYear == 0)
cout << month[num] << " has " << days[num] + 1 << endl;
else
cout << month[num] << " has " << days[num] << endl;
}
else
{
// Decrement by 1.
num--;
// Display month and the number of days.
cout << month[num] << " has " << days[num] << endl;
}
// Prompt for continuance.
cout << "Would you like to run program again? (yes/no) ";
cin >> choice;
}
else
{
// Error message
cout << "Please enter a numerical month number 1-12"<< endl << endl;
// Prompt
cout << "Would you like to continue? (yes/no) ";
cin >> choice;
}
cout << endl;
} while ( choice != "no");
return 0;
}
|