2009-09-12 30 views
1

這是我的代碼閱讀和檢查人品問題

#include<stdio.h> 

int main() 
{ 

    char choice; 

    printf("Do you want to enter a number:"); 
    scanf("%c",&choice); 

    while(choice == 'y') 
    { 
     printf("Entered number\n"); 
     printf("Do you want to enter a number:"); 
     scanf("%c",&choice); 


    } 

    printf("End\n"); 

return 0; 
} 

輸出功率爲

Do you want to enter a number:y 
Entered number 
Do you want to enter a number:End 

首次,它檢查了我的性格是「Y」,但在循環後第一它不會等待用戶輸入,而只是終止循環。可能出了什麼問題?請幫助

+1

你打兩個按鍵 - 'Y',然後輸入(carraige返回)。 – adatapost 2009-09-12 01:50:26

+0

@adatapost scanf在緩衝區中留下換行符......(我認爲)... – aviraldg 2009-09-12 01:57:18

+2

#include 這不是C++。你是否想把這個問題標記爲C? – 2009-09-12 02:08:16

回答