为什么这根本行不通? “ c = getchar()”

时间:2019-01-17 15:38:35

标签: c

我正在学习C,因此我绝对会吮吸...但是我会继续尝试,因为我喜欢它。问题是:我在第16行输入所需的答案,然后程序在此处关闭,而没有提示所需的答案。

#include <stdio.h>
main()
{
    int age, year, yob;
    char c;
    loop:
    printf("Type in the current year > ");
    scanf("%d", &year);
    printf("Type in your year of birth > ");
    scanf("%d", &yob);
    if (yob < 1891 || yob > year) {
        printf("\nStop lying!\n\n");
        goto loop;
    }
    printf("Is your birthday to come? (y/n) > ");
    scanf("%c", &c);
    if (c == 'n') {
        age = year - yob;
        printf("\n\tYou are %d years old.\n\n", age);
    }
    if (c == 'y') {
        age = (year - yob) - 1;
        printf("\n\tYou are %d years old.\n\n", age);
    }

}

0 个答案:

没有答案