运行后除了只有输入不正常日期时才会输出“输入错误”,输入正常日期时什么也不输出
#include <stdio.h>
#include <stdbool.h>
/*
功能:根据当天日期输出明天的日期
*/
//定义一个日期类型 形如2018-06-05
struct date {
int day;
int month;
int year;
//编写日期的结构体
};
//判断某年是否为闰年
bool isLeap(struct date d);
//返回某月的总天数
int numberOfDays(struct date d);
int main(int argc, char const *argv[])
{
struct date today, tomorrow;
printf("输入今天的日期:(year mm dd)");
scanf_s("%i %i %i", &today.year, &today.month, &today.day);
if (today.day < 1 || today.day>31 || today.month < 1 || today.month>12)
printf("输入有误!!\n");
return 0;
if (today.day != numberOfDays(today))
{
tomorrow.day = today.day + 1;
tomorrow.month = today.month;
tomorrow.year = today.year;
}
else if (today.month == 12)
{
tomorrow.day = 1;
tomorrow.month = 1;
tomorrow.year = today.year + 1;
}
else
{
tomorrow.day = 1;
tomorrow.month = today.month + 1;
tomorrow.year = today.year;
}
printf("明天的日期是: %i-%i-%i", tomorrow.year, tomorrow.month, tomorrow.day);
return 0;
}
int numberOfDays(struct date d)
{
int days;
//每个月份的天数
const int daysPerMonth[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
if (2 == d.month && isLeap(d))
{
days = 29;
}
else {
days = daysPerMonth[d.month];
}
return days;
}
bool isLeap(struct date d)
{
bool leap = false;
if ((d.year % 4 == 0 && d.year % 100 != 0) || d.year % 400 == 0)
{
leap = true;
}
return leap;