當我執行下面的程序時,它獲取用戶輸入的帳戶詳細信息,然後正確打印,但無法讀取opt值(y/n)。它會再次自動調用。當用戶輸入「n」時,如何讓程序退出?關於使用scanf輸入的問題
char opt;
do
{
//Getting user input
printf("\n Enter the Account Number:\n ");
scanf("%d",&gAccNo_i);
printf("\n Enter the Account Holder's Name:\n ");
scanf("%s",gCustName_c);
printf("\n Enter the Balance Amount:\n ");
scanf("%f",&gBlncAmt_f);
//Printing the input data.
printf("\n Account Number : %d",gAccNo_i);
printf("\n Customer Name : %s",gCustName_c);
printf("\n Balance Amount : %f",gBlncAmt_f);
printf("\n Do u want to wish to continue?(y/n)");
scanf("%c",&opt);
}while(opt!='n');
這是一次機會作業嗎? – 2011-03-05 07:13:19
'opt'在你期望它包含'n'時有什麼值? – tgdavies 2011-03-05 07:15:26
開關盒?什麼? – quasiverse 2011-03-05 07:15:45