ถามเรื่องหลูบ do-while ค่ะ
#include <stdlib.h> #include <stdlib.h> main() { char choice;
clrscr();
do{ gotoxy(10,5); printf("Input choice :" ); gotoxy(25,5); clreol(); gotoxy(25,5); scanf("%c",&choice);
}while(choice != '1' && choice !='0');
switch(choice){
case "1": printf("Yes"); break;
case "0": printf("No"); break;
default : exit; } getch(); }
ต้องการให้ค่าที่รับเข้ามาที่เป็น 1 กับ 0 ทำงานเท่านั้น นอกนั้นถ้ารับเข้ามาให้วนรับใหม่ อันนี้ลองคอมไพล์แล้วผ่านแต่มีช่องโหว่งว่าถ้าเราพิมพ์ตัวเลข ที่มากกว่า 9 จะทำงานหมดเลยอ่ะ แก้ให้หน่อยนะคะ งงจัง
|