想了很久,找不出哪里出错了,希望大家能帮帮我
#include<stdio.h>int main (void)
{
int year1,year2,month1,month2,date1,date2,i,j,total_year_days=0,total_month_days1=0,total_month_days2=0,total_days;
printf("pealse input your birth day(year,month,date):\n");
scanf("%d,%d,%d",&year1,&month1,&date1);
printf("pealse input nowaday day(year,month,date):\n");
scanf("%d,%d,%d",&year2,&month2,&date2);
for(i=year1;i<year2;i++)
{
if(i%4==0&&i%100!=0||i%400==0)
total_year_days=total_year_days+366;
else
total_year_days=total_year_days+365;
}
for(j=1;j<month1;j++)
{
if(j==1,j==3,j==5,j==7,j==8,j==10,j==12)
total_month_days1=total_month_days1+31;
if(j==4,j==6,j==9,j==11)
total_month_days1=total_month_days1+30;
if(j==2)
{
if(year1%4==0&&year1%100!=0||year1%400==0)
total_month_days1=total_month_days1+29;
else
total_month_days1=total_month_days1+28;
}
}
for(j=1;j<month2;j++)
{
if(j==1,j==3,j==5,j==7,j==8,j==10,j==12)
total_month_days2=total_month_days2+31;
if(j==4,j==6,j==9,j==11)
total_month_days2=total_month_days2+30;
if(j==2)
{
if(year2%4==0&&year2%100!=0||year2%400==0)
total_month_days2=total_month_days2+29;
else
total_month_days2=total_month_days2+28;
}
}
total_days=total_year_days+total_month_days2+date2-total_month_days1-date1;
printf("%d\n",total_days);
return 0;
}
/*year1,month1,date1是出生年月日,year2,month2,date2是今天年月日,total_year_days是从出生年到今年上一年总天数,total_month_days1=0出生年份1月到出生前一月总天数,total_month_days2=0今年1月到这个月前一月总天,total_days活了的天数。
主要问题:比如1990.3.11到1991~2011.1~3.1~30是对的如果现在月份大于出生月份就不对了!
请学长们帮帮忙