課金システムのプログラムを書いています。プログラムで do-while ループを使用しています。そして、プログラムはユーザーの入力に従って実行されます。ユーザーが実行を継続したい場合、プログラムは続行されます。しかし、私は実行で問題を抱えています。シンプルな do-while ループでロジックを試していました。単純な do-while ループでも同じ問題が発生します。
Problem is: If the input is yes, the program does not get the further input from user.
その単純な do-while ループは次のとおりです。
#include <stdio.h>
main()
{
int c;
char ch;
do
{
printf("enter the no less then 4:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("In 1\n");
break;
case 2:
printf("In 2\n");
break;
case 3:
printf("In 3\n");
break;
}
printf("do u want to continue?:");
ch=getchar();
}while(ch=='y');
}
プログラムwhile(ch != 'n')
の代わりに置くと、正常に動作します。while(ch=='y')
この背後にある問題を理解できませんでした。これを修正するのを手伝ってください。そして、この問題について説明してください。よろしくお願いします。