下面是我编写的一个 do-while 循环。当我运行它时,前两个案例完成了它们的工作并完美运行。然而。第三种情况应该退出程序,但它什么也不做,只是回到 do-while 循环开头的一系列 printf 语句。关于我做错了什么的任何建议?
do
{
printf("Choose one of the following (1, 2, or 3) \n");
printf("1. Find GCD of two positive integers\n");
printf("2. Sort 3 integers in the ascending order\n");
printf("3. Quit the program\n");
printf("Please enter your choice: ");
scanf("%d", &option);
switch (option)
{
case 1:
gcd(p, q);
printf("\nDo you want to try again? Say Y(es) or N(o): ");
getchar();
response = getchar();
break;
case 2:
sort(p, q, r);
printf("\nDo you want to try again? Say Y(es) or N(o): ");
getchar();
response = getchar();
break;
case 3:
break;
}
}
while (response == 'Y' || response == 'y'); //Condition that will determine whether or not the loop continues to run.
printf("\nThank you for using my progam. Goodbye!\n\n");
return 0;
}