想学习的小猫猫 2021-11-15 08:36 采纳率: 0%
浏览 129

根据当天日期,输出明天日期

运行后除了只有输入不正常日期时才会输出“输入错误”,输入正常日期时什么也不输出

#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;

img

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-11-15 08:40
    关注

    27行return 0了啊
    return 0应该是if的代码块,修改如下:
    if (today.day < 1 || today.day>31 || today.month < 1 || today.month>12)
    {
    printf("输入有误!!\n");
    return 0;
    }

    评论 编辑记录

报告相同问题?

问题事件

  • 创建了问题 11月15日

悬赏问题

  • ¥15 ue2.6.12版本用的若以,安装gojs,引入import * as go from 'gojs';报错
  • ¥15 服务器上的网站安装php5.6版本
  • ¥15 ModuleNotFoundError: No module named 'torch.utils._import_utils' 是缺少什么
  • ¥15 请大咖一起探索iptv 直播源的hls通过反向代理解密
  • ¥100 寻找技术员 云闪付tn转h5输入卡号付款的链接 重酬!
  • ¥100 科大讯飞语音唤醒词,unbuntu环境,报错
  • ¥50 python写segy数据时出错2
  • ¥20 关于R studio 做精确稳定检验的问题!(语言-r语言)
  • ¥50 用贝叶斯决策方法,设计CAD程序
  • ¥20 关于#目标检测#的问题:(qq收集表到时间才能填写,填写的份数有上限)