Write a program that accepts dates written in numerical form and outputs in complete form
#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;
}
Comments
Leave a comment