当输入日期为2018 11 11时显示是捕鱼
但是答案是晒网
实在是看不出来那里错了
#include<stdio.h>
#include<windows.h>
typedef struct
{
int year;
int month;
int day;
} Date;
typedef enum {saiwang,dayu} Workstatus;
int monthdays(int year,int month)
{
int days[13]= {0,31,28,31,30,31,30,31,31,30,31,30,31};
if((year%4==0&&year%100!=0)||(year%400==0))
days[2]=29;
int day=days[month];
return day;
}
int delta_T(Date start,Date end)
{
int dayyears=(end.year-start.year)*365;
int runyears=0;
for(int i=start.year; i<end.year; i++)
{
if((i%4==0&&i%100!=0)||(i%400==0))
runyears++;
}
int daymonths=0;
for(int i=start.month; i<end.month; i++)
{
daymonths+=monthdays(end.year,i);
}
int days=end.day-start.day;
int todays=dayyears+runyears+daymonths+days;
return todays;
}
Workstatus workstatusoneday(Date start,Date end)
{
int todays=delta_T(start,end);
if(todays%5==0||todays%5==4)
{
Workstatus workstatus1=saiwang;
return workstatus1;
}
else
{
Workstatus workstatus1=dayu;
return workstatus1;
}
}
void inputenddate(Date *end)
{
puts("please input end date(xxxx xx xx):");
int flag=1;
while(flag)
{
int maxdays=0;
Date temp= {0,0,0};
int x=scanf("%d%d%d",&temp.year,&temp.month,&temp.day);
if(x!=3)
{
puts("Data error,please input number(int)!\a");
while(getchar()!='\n');
continue;
}
else
{
if(temp.year<1990)
{
puts("year input error!(year>=1990)\a");
while(getchar()!='\n');
continue;
}
if(temp.month<=0||temp.month>12)
{
puts("month input error!(0<month<=12)\a");
while(getchar()!='\n');
continue;
}
else
maxdays=monthdays(temp.year,temp.month);
}
if(temp.day<0||temp.day>maxdays)
{
printf("day input error!(0<day<=%d)\a\n",maxdays);
while(getchar()!='\n');
continue;
}
else
{
(*end).year=temp.year;
(*end).month=temp.month;
(*end).day=temp.day;
flag=0;
}
}
}
int main()
{
system("color 0c");
Date start= {1990,1,1},end;
int x=1;
while(x)
{
inputenddate(&end);
delta_T(start,end);
Workstatus flag=workstatusoneday(start,end);
if(flag==saiwang)
printf("%-5d年 %-5d月 %-5d日 这天在晒网!\n",end.year,end.month,end.day);
else
printf("%-5d年 %-5d月 %-5d日 这天在捕鱼!\n",end.year,end.month,end.day);
puts("Whether to continue,enter Y to continue,enter any other character!");
fgetc(stdin);
char ch=getchar();
if(ch!='Y'&&ch!='y')
x=0;
}
return 0;
}