Code:
#include <stdio.h>
#include <time.h>
int days, month, year, days_1, month_1, year_1, leapy, ndays, ddays, days_total;
int daysinmonth(int month) /*there is a problem in this statement, your printf is reading out ridiculous numbers for days, don't forget to ask*/
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
return 31;
case 2:
return 28;
case 4:
case 6:
case 9:
case 11:
return 30;
default:
return -1;
}
}
int leap(int year)
{
if(year%400 ==0 || (year%100 != 0 && year%4 == 0))
{
leapy=1;
}
else
{
leapy=0;
}
}
daysinyear(int days, int month, int days_1, int month_1)
{
int i=0;
days_total = daysinmonth(month) - days;
for(i = month+1;i < month_1 - 1;++i);
days_total += daysinmonth(i);
days_total += days_1;
return days_total;
}
int main(void)
{
int days_1, month_1, year_1;
char a, b, a1, b1;
printf("intput a date in the follwing format:\n");
printf("mmddyyyy: in other words the two digit day,two digit month,\n");
printf("and four digit year, with no slashes or heifens anywhere.\n");
scanf("%d%c%d%c%d", &month, &a, &days, &b, &year);
if(month<0 || month>12 || days<0 || days>31 || year<0)
{
printf("data not valid");
}
printf("enter the later date in the same format:\n");
scanf("%d%c%d%c%d", &month_1, &a1, &days_1, &b1, &year_1);
daysinmonth(month);
daysinmonth(month_1);
printf("days_total=%d",daysinyear(days, month, days_1, month_1));
return 0;
}
When I run this code it reads out 60 days for the dates 1/1/1 to 1/2/1. The logic you use seems good, I'm wondering if it's maybe the way I'm calling the daysinmonth or daysinyear function? thanks for all the help.