write and run aprogram that asks the user to enter the date in the following for
ID: 3611180 • Letter: W
Question
write and run aprogram that asks the user to enter the date in the followingform: dd mm yyyy, and then the program will print the entered datein a literal form using a switch statement. The programe will keepasking the user to enter the date while the entered day, month oryear is out of range. (i.e. the value of month, day and year shouldbe in the followng range : 1<=m<=12, 1<=d<=31,y>0
sample output
enter the date : 15 4 2009
the date in literal form: April 15, 2009
press any key to continue write and run aprogram that asks the user to enter the date in the following
form: dd mm yyyy, and then the program will print the entered datein a literal form using a switch statement. The programe will keepasking the user to enter the date while the entered day, month oryear is out of range. (i.e. the value of month, day and year shouldbe in the followng range : 1<=m<=12, 1<=d<=31,y>0
sample output
enter the date : 15 4 2009
the date in literal form: April 15, 2009
press any key to continue
Explanation / Answer
#include <iostream>
using namespace std;
int main(){
int d,m,y;
cout<<"Enter date:";
cin>>d>>m>>y;
while(d>=1 && d<=31 && m>=1 &&m<=12)
{
switch(m){
case 1:
break;
cout<<"Jan "<<d<<","<<y<<endl;
case 2:
cout<<"Feb "<<d<<","<<y<<endl;
break;
case 3:
cout<<"March "<<d<<","<<y<<endl;
break;
case 4:
cout<<"April "<<d<<","<<y<<endl;
break;
case 5:
cout<<"May "<<d<<","<<y<<endl;
break;
case 6:
cout<<"June "<<d<<","<<y<<endl;
break;
case 7:
cout<<"July "<<d<<","<<y<<endl;
break;
case 8:
cout<<"Augest "<<d<<","<<y<<endl;
break;
case 9:
cout<<"September "<<d<<","<<y<<endl;
break;
case 10:
cout<<"October "<<d<<","<<y<<endl;
break;
case 11:
cout<<"November "<<d<<","<<y<<endl;
break;
case 12:
cout<<"December "<<d<<","<<y<<endl;
break;
}
cout<<"Enter date:";
cin>>d>>m>>y;
}
cout<<endl;
system("pause");
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.