询问用户的出生年份并计算他们在当年的年龄。

#include <stdio.h>
#define CURRENTYEAR 2020

int main()
{
    int yearBorn, age;
    printf("What year were you born?/n");
    scanf(" %d", &yearBorn);

    if (yearBorn > CURRENTYEAR){
        printf("wrong input!/n");
        printf("What year were you born?/n");
        scanf(" %d", &yearBorn);
    }

    age = CURRENTYEAR - yearBorn;
    printf("/nSo this year you will turn %d on your birthday!/n",age);

    if ((yearBorn % 4) == 0){
        printf("/nYou were born in a Leap Year--cool!/n");
    }
    return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266780.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论