Answer to Question #243081 in C++ for xtian

Question #243081

Write a program that accepts dates written in numerical form and outputs in complete form


1
Expert's answer
2021-09-28T00:49:41-0400
#include <iostream>
#include <cstring>
using namespace std;
int main(){
    int dd, mm, yy;
    cout<<"Input date in dd/mm//yyyy format: ";
    char c; cin>>dd>>c>>mm>>c>>yy;


    char month[10];
    switch(mm){
        case 1: strcpy(month, "January"); break;
        case 2: strcpy(month, "February"); break;
        case 3: strcpy(month, "March"); break;
        case 4: strcpy(month, "April"); break;
        case 5: strcpy(month, "May"); break;
        case 6: strcpy(month, "June"); break;
        case 7: strcpy(month, "July"); break;
        case 8: strcpy(month, "August"); break;
        case 9: strcpy(month, "September"); break;
        case 10: strcpy(month, "October"); break;
        case 11: strcpy(month, "November"); break;
        case 12: strcpy(month, "December"); break;
        default: cout<<"Invalid month"; return -1;
    }


    cout<<dd;
    switch(dd % 10){
        case 1: cout<<"st "; break;
        case 2: cout<<"nd "; break;
        case 3: cout<<"rd "; break;
        case 4:;
        case 5:;
        case 6:;
        case 7:;
        case 8:;
        case 9: cout<<"th "; break;
        default: break;
    }


    cout<<month<<" "<<yy<<endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS