写了一个程序 想补充完善一下
程序的功能是输入年月日 输出下一天 ReturnNextDay函数返回一个值赋给Nextday
主要功能已经完全实现了
现在想:
一:当用户输入出错时可以重新输入 而不是像现在只提示有错
二:当一次输入输出成功完成后 如果用户想要继续 那么就重新输入
主要是想在用户输入有误时和用户希望一次运行完以后继续运行一次时循环执行 循环写了很长时间 总是不对 求助各位高手给指点一下
代码如下
int IsLeapYear(int Year);
int IsCurrentDate(int Year,int Month,int Day);
int ReturnNextDay(int Year,int Month,int Day);
int LeapYear_Month_SumDay[12]={31,29,31,30,31,30,31,31,30,31,30,31};
void main()
{ int Year=0,Month=0,Day=0,NextDay=0;
printf("pleace enter a date(example:2007 3 24):\n");
scanf("%d%d%d",&Year,&Month,&Day);
NextDay=ReturnNextDay(Year,Month,Day);
switch (NextDay)
{
case 0:
{printf("\n\error\n\n");
}
case 1:
if (Month==12)
{
Year++;
Month=1;
}
else
{
Month++;
}
}
if (NextDay!=0) printf("The next day you input is %d-%d-%d.\n",Year,Month,NextDay);
}
int IsLeapYear(int Year)
{
if (Year%4==0)
{
if (Year%100==0)
{
if (Year%400==0) return 1;
else return 0;
}
else return 1;}
else return 0; }
int IsCurrentDate(int Year,int Month,int Day){
if ((Year<0) || (Year>9999) || (Month>12) || (Month<1) || (Day<1) ||(Day>31) )
return 0;
else return 1;
}
int ReturnNextDay(int Year,int Month,int Day)
{
int ThisMonthSumDay;
if (IsCurrentDate(Year,Month,Day)==1)
{
ThisMonthSumDay=LeapYear_Month_SumDay[Month-1];
if (Month==2)
{
if (IsLeapYear(Year)==0) ThisMonthSumDay--;
}
if (Day<ThisMonthSumDay)
{
return ++Day;
}
else
{
if (Day==ThisMonthSumDay)
return 1;
else
return 0;
}
}
else return 0;
}
----------------解决方案--------------------------------------------------------
# include<stdio.h>
int IsLeapYear(int Year);
int IsCurrentDate(int Year,int Month,int Day);
int ReturnNextDay(int Year,int Month,int Day);
int LeapYear_Month_SumDay[12]={31,29,31,30,31,30,31,31,30,31,30,31};
void main()
{ int Year=0,Month=0,Day=0,NextDay=0;
char ch='Y';
while(1)
{
fflush(stdin);
do{printf("pleace enter a date(example:2007 3 24):\n");
scanf("%d%d%d",&Year,&Month,&Day);
NextDay=ReturnNextDay(Year,Month,Day);
if(NextDay!=0)
break;
else printf("\nerror!\n\n");}while(1);
switch (NextDay)
{
case 1:
if (Month==12)
{
Year++;
Month=1;
}
else
{
Month++;
}
}
if (NextDay!=0) printf("The next day you input is %d-%d-%d.\n",Year,Month,NextDay);
printf("continue? 'Y'or'N'?\n");
getchar();
ch=getchar();
getchar();
if(ch=='N')
break;
}
return;
}
int IsLeapYear(int Year)
{
if (Year%4==0)
{
if (Year%100==0)
{
if (Year%400==0) return 1;
else return 0;
}
else return 1;}
else return 0; }
你的程序格式不太好,,,,,,,
----------------解决方案--------------------------------------------------------