是否有可能有一个嵌套的条件语句?

时间:2016-08-19 17:07:30

标签: c do-while

我正在尝试do-while条件,而在其中有另一个,我在#34中有问题;你想继续吗?",它跳过它..有什么不对我的代码?

do {
    printf("\nEnter the start value:");
    scanf("%d", &start_value);
    printf("\nEnter the end value:");
    scanf("%d", &end value);
    printf("\nEnter the interval value:");
    scanf("%d", &interval_value);
    while (start_value <= end_value) {
        printf("%d ", start_value);
        start_value = start_value + interval_value;
    }
    printf("\nDo you want to continue?");
    scanf("%c", &answer);
} while (answer != 'N' || answer != 'n');

1 个答案:

答案 0 :(得分:3)

您的条件声明

while(answer != 'N' || answer != 'n');

总是true。我建议

while(answer != 'N' && answer != 'n');

(除了@SouravGhosh上面的第一条评论,它清除输入缓冲区中的newline左侧)