c语言中循环控制语句 (do语句,限制用户输入数值的范围)

 

c语言中循环控制语句(do语句,限制用户输入数值的范围)

1、

#include <stdio.h>

int main(void)
{
    int i;
    do
    {
        puts("please input an integer! the range is 0-2!");
        printf("i = "); scanf("%d", &i);
    }
    while (i < 0 || i > 2);     ## 此句判断为非0,则继续执行循环体
    switch (i)
    {
        case 0: puts("you had choose stone!"); break;
        case 1: puts("you had choose scissors!"); break;
        case 2: puts("you had choose clothes!"); break;
    }
    return 0;
}

 

posted @ 2021-03-15 10:58  小鲨鱼2018  阅读(1554)  评论(0编辑  收藏  举报