how to display this date format : 0x/0y/0z

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 1samir
    New Member
    • Mar 2012
    • 1

    how to display this date format : 0x/0y/0z

    int d,m,y;
    printf("give the date of your birth dd/mm/yyyy \n");
    scanf("%2d %2d %4d", &d, &m, &y);
    if (y>2000){printf ("the date is : %2d / %2d / %2d ", d, m, y-2000);}
    else{printf("th e date is %2d / %2d / %2d ", d, m, y-1900);}

    //ex: {13/01/2005
    the date is : 13/1/5}
    i want 2 dispaly 13/01/05
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    Why would you want to repeat an error like m=13?
    to provide leading zeros for d and m you could do something like this:
    Code:
    if(d<10 || mm<10)
    cout<<"date: "<<'0'<<d<<'/'<<'0'<<mm<<'/'<<yyyy;
    else cout<<"date: "<<d<<'/'<<mm<<'/'<<yyyy;
    your code for controlling yyyy before 2000 would provide no clue as to century.

    Comment

    Working...