考研的小杨 2022-09-25 19:13 采纳率: 93.8%
浏览 47
已结题

C语言中bool关键字报错问题


#include<stdio.h>
#include<stdbool.h>

struct date{
    int month;
    int day;
    int year;
};

bool isLeap(struct date d);
int numberOfDays(struct date d);

int main(int argc,char const *argv[])
{
    struct date today,tomorrow;
    printf("Enter today's date (mm dd yy):");
    scanf("%d %d %d",&today.month,&today.day,&today.year);
    
    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("Tomorrow's date is %s-%s-%s.\n");
    
    return 0;
}

int numberOfDays(struct date d)
{
    int days;
    
    const int daysPerMonth[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    
    if(d.month == 2 && isLeap(d))
        days = 29;
    else
        days = daysPerMonth[d.month-1];
        
        return days;
}

bool isLeap(struct date d)
{
    bool leap = false;
    
    if((d.year %4 == 0 && d.year %1000 != 0) || d.year%400 == 0)
        leap = ture;     //[Error] 'ture' undeclared (first use in this function)
}

最后那里为什么会出现错误,明明都加了#include<stdbool.h>头文件的??

  • 写回答

2条回答 默认 最新

  • 心寒丶 全栈领域优质创作者 2022-09-25 19:17
    关注

    leap = ture; 单词错了吧 true?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月3日
  • 已采纳回答 9月25日
  • 创建了问题 9月25日

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)