2012-12-08 106 views
0

我需要一個條件爲do-while循環,這意味着該循環被重複(請求用戶再次輸入數據),直到它是一個整數和1到25之間條件來檢查用戶輸入

while (!isdigit(data) || data < 1 || data > 25); 

這只是拋出一個運行時錯誤,我不知道爲什麼。

回答

0

試試這個:

do { 

    /* Read from input and store it in data */ 

} while(!isdigit(data) || !(data > 1 && data < 25)); 
+0

不要使用'scanf' - http://c-faq.com/stdio/scanfprobs.html – user93353

+0

感謝。檢查數字> 1且<25有效,但如果我在其中輸入一個字母將繼續 – user1827332