Problem: Write and execute a program to accept two dates in the format dd/mm/yyyy and print the number of days between the two dates if both the dates are valid. - C language
I know the general formula for the code I'm just not sure what I should make for the statements to execute it properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <stdio.h>
int dateSerial (int ,int, int );
int main(void) {
int m,d,y;
printf("Enter one date in the format of dd/mm/yyyy : ");
scanf("%d %d %d",&d,&m,&y);
printf("Enter another date in the format of dd/mm/yyyy : ");
scanf("%d %d %d",&d,&m,&y);
m = (m + 9) % 12;
y = y - m/10;
return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + (d-1);
}
Line 11: You're overlaying the values that were read in at line 8.
Line 2: You have a prototype for dateSerial(), but never implement it. If you want to find the number of days between two dates, you want to take the different between two serial dates. Keep in mind the dates may not be in order.
if both the dates are valid
I see no checking that the dates are valid.
Line 15: You probably want to printf the difference between two dates, rather than returning a calculation to the operating system.