我使用是/否用戶提示來確定用戶是否想要瀏覽程序或退出程序......當您輸入y或Y時,它將再次通過程序。但是,任何其他字符,不僅僅是n或N,都會中斷程序。我想知道如何解決這個問題?是/否C中的提示?
int main() {
unsigned num;
char response;
do {
printf("Please enter a positive integer greater than 1 and less than 2000: ");
scanf("%d", & num);
if(num > 1 && num < 2000) {
printf("All the prime factors of %d are given below: \n", num);
printPrimeFactors(num);
printf("\n\nThe distinct prime factors of %d are given below: \n", num);
printDistinctPrimeFactors(num);
} else {
printf("Sorry that number does not fall within the given range.\n");
}
printf("\n\nDo you want to try another number? Say Y(es) or N(o): ");
getchar();
response = getchar();
}
while (response == 'Y' || response == 'y'); // if response is Y or y then program runs again
printf("Thank you for using my program. Good Bye!\n\n"); //if not Y or y, program terminates
return 0;
}
如果Y使它們繼續,N使它們退出,那麼您希望其他字母做什麼? – Pete
我希望其他字母不能像N一樣停止播放...喜歡「你輸入了非Yes或No以外的內容,請重試」 –
嗯,這不正是你想要的嗎?或者需要修正什麼? – 2013-02-01 19:41:35