新手求助C++的一个疑惑
先看程序:#include<iostream.h>
void main()
{
int year,i;
cout<<"year=";
cin>>year;
if(year<0)
cout<<"input error!"<<endl;
while(year>=0 && year<=130)
{
i=year/10;
switch(i)
{
case 0:
cout<<"小孩"<<endl;
break;
case 1:
cout<<"少年"<<endl;
break;
case 2:
cout<<"青年"<<endl;
break;
case 3:
case 4:
cout<<"中年"<<endl;
break;
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
case 11:
case 12:
case 13:
cout<<"老年"<<endl;
break;
default:
cout<<"input error!"<<endl;
}
cout<<"input year=";
cin>>year;
}
}
问当我输入year值为小数的时候,为什么会进入死循环? 而且循环输出内容都为:“input year =小孩”