Question #47571

Write a program that accepts dates written in numerical form and then output them as a complete form. For example, the input:

2 26 1986
Should produce the output: February 26, 1986
In Switch Case

Expert's answer

Answer on Question #47571, Programming, C++

Problem.

Write a program that accepts dates written in numerical form and then output them as a complete form. For example, the input:

2 26 1986

Should produce the output: February 26, 1986

In Switch Case

Solution.

Code


#include <iostream>
#include <string>
using namespace std;
int main() {
    int day;
    int month;
    string monthAsStr;
    int year;
    // Input
    cin >> month >> day >> year;
    switch (month) {
        case 1: monthAsStr = "January"; break;
        case 2: monthAsStr = "February"; break;
        case 3: monthAsStr = "March"; break;
        case 4: monthAsStr = "April"; break;
        case 5: monthAsStr = "May"; break;
        case 6: monthAsStr = "June"; break;
        case 7: monthAsStr = "July"; break;
        case 8: monthAsStr = "August"; break;
        case 9: monthAsStr = "September"; break;
        case 10: monthAsStr = "October"; break;
        case 11: monthAsStr = "November"; break;
        case 12: monthAsStr = "December"; break;
    }
    // Output
    cout << monthAsStr << " " << day << ", " << year;
    return 0;
}

Result

2 26 1986

February 26, 1986

://www.AssignmentExpert.com/</string></iostream>

LATEST TUTORIALS
APPROVED BY CLIENTS