Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Homework HelpRSS Feeds

Program that takes short date from a user and displays medium date

Posted By: Easy Tutor     Category: C++ Programming     Views: 2049

Write a program that takes short date from a user and displays medium date in format 01-10-99

Code for Program that takes short date from a user and displays medium date in C++ Programming

#include<iostream.h>
#include<conio.h>
void main()
{ 
shortint month,day,k,rev=0,c=1,m=0,v=1;

int year;

clrscr();

cout<<"\nEnter Day of the Month:-";

cin>>day;

cout<<"\nEnter Month in Two Digit:-";

cin>>month;

cout<<"\nEnter Year in Four Digit:-";

cin>>year;

clrscr();

////VALIDATION FOR ENTERING ILLEGAL DAYS////if(month==2)

{

if(year%4==0)

{

if(day>29 || day<=0)

{

cout<<"Entered Date is Illegal";

goto end;

}

}

else

{

if(day>28 || day<=0)

{

cout<<"Entered Date is Illegal";

goto end; 

}

}

}

elseif(month==1||month==3||month==5||month==7||month==8||month==10||month==12)

{

if(day>31 || day<=0)

{

cout<<"Entered Date is Illegal";

goto end;

} 

}

elseif(month==4||month==6||month==9||month==11)

{

if(day>30 || day<=0)

{

cout<<"Entered Date is Illegal";

goto end;

}

}

////VALIDATION FOR ENTERING ILLEGAL MONTH////if(month>12 || month<1)

{

cout<<"Entered Date is Illegal";

goto end;

}

////VALIDATION FOR YEAR////if(year<1000 ||year>=2100)

{

cout< <"Entered Date is Illegal";

goto end;

}

//FOR DAYswitch(day)

{

case 1 :

case 21 :

case 31 :cout<<day<<"st-";

break;

case 2 :

case 22 :

cout<<day<<"nd-";

break;

case 3 :

case 23 :

cout<<day<<"rd-";

break;

default :

cout<<day<<"th-";

break;

} 

//FOR MONTHswitch(month)

{

case 1:cout<< "Jan-";

break;

case 2:cout<<"Feb-";

break;

case 3:cout<<"Mar-";

break;

case 4:cout< <"Apr-";

break;

case 5:cout<<"May- ";

break;

case 6:cout<<"Jun-";

break;

case 7:cout<<"Jul-";

break;

case 8:cout<<"Aug-";

break;

case 9:cout<<"Sep-";

break;

case 10:cout<<"Oct-";

break;

case 11:cout<<"Nov-";

break;

case 12:cout<<"Dec-"; 

break;

}

//FOR YEARif(year==2000)

goto direct;

while(year>0)

{

k=year%10;

rev=rev*10+k;

year=year/10;

v++;

if(v>2)

goto down;

}

down:

while(rev>0)

{

k=rev%10;

m=m*10+k;

rev=rev/10;

c++;

if(c >2)

gotoout;

}

out:

cout<<m;

goto end;

direct:

cout<<"00 ";

end:

getch();

}


     
  
Share: 



Easy Tutor
Easy Tutor author of Program that takes short date from a user and displays medium date is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!