其他分享
首页 > 其他分享> > c语言中利用do while循环语句限制用户的输入范围

c语言中利用do while循环语句限制用户的输入范围

作者:互联网

 

001、

#include <stdio.h>

int main(void)
{
    int i;
    
    do
    {
        puts("0: stone;   1: scissors;   2: colth");
        printf("i = "); scanf("%d", &i);
        
        if(i > 2 || i <0)
        {
            puts("the proper range is 0 ~ 2.");
        }
    }
    while(i > 2 || i < 0);
    
    switch(i)
    {
        case 0: puts("you had choosed: stone"); break;
        case 1: puts("you had choosed: scissors"); break;
        case 2: puts("you had choosed: cloth"); break;
    }
    
    return 0;
}

 

标签:语句,do,puts,int,had,break,case,while,choosed
来源: https://www.cnblogs.com/liujiaxin2018/p/16578427.html