c++我要考试作业

来源:百度知道 编辑:UC知道 时间:2024/06/26 00:24:11
#include <stdio.h>
#include <stdlib.h>
struct date
{
int year,month,day;
};
void main()
{
char yn;
struct date s1;
while(1)
{
printf("请输入一个日期:年\t月\t日\n");
scanf("%d%d%d",&s1.year,&s1.month,&s1.day);
if(s1.year<1000||s1.year>100000)
{
printf("无效值!");
exit(0);
}
if(s1.month<1||s1.month>12)
{
printf("无效值!");
exit(0);

}
switch(s1.month)
{
case 1:
case 3:
case 4:
case 5:
case 7:
case 8:
case 10:
case 12:
if(s1.day<=0 && s1.day>31)
{
printf("输入有误!\n");
continue;
}
else if(s1.month=12 && s1.day==31)
{
s1.year++;
s1.month=1;
s1.day=1;

printf("后一天的日期为:%d\n+%d\n",s1.year,s1.month,s1.day);少了个%d
if(yn=="n")应为'n'
而且你算法还有问题,没判断XX年12月31日输入后年要加1
具体你改改吧 实在做不出来在给我发信息吧