English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

for example if the user entered month 2 and year 2000,the algorithm should display the february 2000.

2006-11-02 20:27:38 · 2 answers · asked by vienaz 1 in Computers & Internet Programming & Design

2 answers

OK, this question is *REALLY* confusing. You want it to display what? The name of the month? The number of days in the month? Whether it's a leap year?? The program below translates a month and year in numerical format to the English name of the month and the numerical year. If this is not what you want please clarify your question.

#include
#include
using namespace std;

char *months[] = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"};


int main()
{
int month, year;
ostringstream os;

month = -1;
while (month < 1 || month > 12) {
cout << "Month: ";
cin >> month;
if (month < 1 || month > 12) cerr << "invalid month" << endl;
}

cout << "Year: ";
cin >> year;

os << months[month-1] << " " << year << endl;
cout << os.str();

return 0;
}

2006-11-02 20:46:34 · answer #1 · answered by renegadeconformist 2 · 0 0

Every month has at least 28 days ?

2006-11-03 04:43:27 · answer #2 · answered by pappy 6 · 0 0

fedest.com, questions and answers