【发布时间】:2016-08-19 17:07:29
【问题描述】:
我正在尝试 do-while 条件,其中还有一个 while,我在“你想继续吗?”中遇到问题,它正在跳过它。我的代码有什么问题吗?
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');
【问题讨论】:
-
scanf("%c", &answer);-->scanf(" %c", &answer); -
嗯?您正在为变量“first”和“second”赋值,然后不再使用它们。
-
好的,Weather Vane 的回答也添加了一个非常有效的观点,但是“跳过”部分是骗人的。如果有人不同意简历,请告诉我。
-
start_value和end_value应该是first和second,反之亦然。 -
@SouravGhosh:这个副本质量很差。我敢肯定还有更好的。