Okay, in this program I want a user to enter a date in the form of mm/dd/yy, and then have it displayed in the form yymmdd.
Although I rearranged the variables in the printf string, so I thought they would display in the order I asked, they did not, they displayed the date exactly as the user input. (but added two zeros, one at the beginning and one at the end, why?) Also, as I entered the date (as the user) it just entered as 110671. Can I get my program to insert a / immediately after I input the first two integers, then another / before the last two? Without doing a scanf string just for the first two, then a printf string just for the /, then a scanf string for the next two digits, then another printf string for another /, etc, etc??? Here's my code... below the code is the output of the program....
Here is the output.....
Enter a date (mm/dd/yy):110671
You entered the date: 0 110671 0
Scott-Deans-MacBook-Pro:documents scottdean$
Although I rearranged the variables in the printf string, so I thought they would display in the order I asked, they did not, they displayed the date exactly as the user input. (but added two zeros, one at the beginning and one at the end, why?) Also, as I entered the date (as the user) it just entered as 110671. Can I get my program to insert a / immediately after I input the first two integers, then another / before the last two? Without doing a scanf string just for the first two, then a printf string just for the /, then a scanf string for the next two digits, then another printf string for another /, etc, etc??? Here's my code... below the code is the output of the program....
Code:
#include <stdio.h>
main ( )
{
int month ;
int day ;
int year ;
printf ("Enter a date (mm/dd/yy):") ;
scanf ("%d %d %d", &month, &day, &year) ;
printf ("You entered the date: %d %d %d\n", year, month, day) ;
return 0 ;
}
Enter a date (mm/dd/yy):110671
You entered the date: 0 110671 0
Scott-Deans-MacBook-Pro:documents scottdean$
Last edited by a moderator: