#include <stdio.h>
void meun(void);
int select(int,int);
int main(void)
{
int a,b,c;
scanf("%d%d",&a,&b);
meun();
while(c=select(a,b)&&c!=4);
{
switch(c)
{
case 1:
printf("1");
case 2:
printf("2");
case 3:
printf("3");
}
}
return 0;
}
void meun(void)
{
printf("Please choose one of the following:");
printf("\n1) copy files 2)move files"
"\n3)remove files 4)quit");
printf("\nEnter the number of your choice:");
}
int select(int m,int n)
{
int t,y,k,statue;
t=m;
m=m>n?m:n;
k=m;
m=t;
n=n<m?n:m;
m=k;
while((statue=scanf("%d",&y))!=1||y>m||y<n)
{
if(statue!=1)
{
printf("please enter number:\n");
meun();
while(getchar()!='\n')
continue;
continue;
}
if(y>m||y<n)
{
printf("please enter number in 1~4:\n");
meun();
}
}
return y;
}
问题在最后那个函数定义上
这个程序的要求是要先输入两个整数作为上下限,然后让用户输入值
范围这里题目里说了是1~4
就是说m=4
n=1
然后是那个while循环
只有不在大于等于1小于等于4这个范围内地错误用户输入才会进入这个while循环,但当输入3的时候这个循环没有结束,也没有返回y的值,这是为什么?
范围1-4指的是菜单选项,和上下限无关吧