找错解决方法
找错
我想返回 switch()
大家看看怎么去做
int chinese_constellation()
{
string constellation[12]={ "猴 ", "鸡 ", "狗 ", "猪 ", "兔 ", "蛇 ", "鼠 ", "龙 ", "虎 ", "牛 ", "马 ", "羊 "};
int y,flag=1,year;
for(;flag==1;)
{
cout < < " enter the year as a number: ";
cin> > year;
if((year> 3000)||(year <1900))
{
cout < < " it is error data, Please enter again: ";
system( "pause ");
return chinese_constellation();
}
else flag=0;
}
y=year%12;
switch(y)
{
case 0:cout < < "this constellation is " < <constellation[0];break;
case 1:cout < < "this constellation is " < <constellation[1];break;
case 2:cout < < "this constellation is " < <constellation[2];break;
case 3:cout < < "this constellation is " < <constellation[3];break;
case 4:cout < < "this constellation is " < <constellation[4];break;
case 5:cout < < "this constellation is " < <constellation[5];break;
case 6:cout < < "this constellation is " < <constellation[6];break;
case 7:cout < < "this constellation is " < <constellation[7];break;
case 8:cout < < "this constellation is " < <constellation[8];break;
case 9:cout < < "this constellation is " < <constellation[9];break;
case 10:cout < < "this constellation is " < <constellation[10];break;
case 11:cout < < "this constellation is " < <constellation[11];break;
default:break;
}
return switch(y);
}
------解决方案--------------------
switch(y)
{
case 0:cout < < "this constellation is " < <constellation[0];break;
case 1:cout < < "this constellation is " < <constellation[1];break;
case 2:cout < < "this constellation is " < <constellation[2];break;
case 3:cout < < "this constellation is " < <constellation[3];break;
case 4:cout < < "this constellation is " < <constellation[4];break;
case 5:cout < < "this constellation is " < <constellation[5];break;
case 6:cout < < "this constellation is " < <constellation[6];break;
我想返回 switch()
大家看看怎么去做
int chinese_constellation()
{
string constellation[12]={ "猴 ", "鸡 ", "狗 ", "猪 ", "兔 ", "蛇 ", "鼠 ", "龙 ", "虎 ", "牛 ", "马 ", "羊 "};
int y,flag=1,year;
for(;flag==1;)
{
cout < < " enter the year as a number: ";
cin> > year;
if((year> 3000)||(year <1900))
{
cout < < " it is error data, Please enter again: ";
system( "pause ");
return chinese_constellation();
}
else flag=0;
}
y=year%12;
switch(y)
{
case 0:cout < < "this constellation is " < <constellation[0];break;
case 1:cout < < "this constellation is " < <constellation[1];break;
case 2:cout < < "this constellation is " < <constellation[2];break;
case 3:cout < < "this constellation is " < <constellation[3];break;
case 4:cout < < "this constellation is " < <constellation[4];break;
case 5:cout < < "this constellation is " < <constellation[5];break;
case 6:cout < < "this constellation is " < <constellation[6];break;
case 7:cout < < "this constellation is " < <constellation[7];break;
case 8:cout < < "this constellation is " < <constellation[8];break;
case 9:cout < < "this constellation is " < <constellation[9];break;
case 10:cout < < "this constellation is " < <constellation[10];break;
case 11:cout < < "this constellation is " < <constellation[11];break;
default:break;
}
return switch(y);
}
------解决方案--------------------
switch(y)
{
case 0:cout < < "this constellation is " < <constellation[0];break;
case 1:cout < < "this constellation is " < <constellation[1];break;
case 2:cout < < "this constellation is " < <constellation[2];break;
case 3:cout < < "this constellation is " < <constellation[3];break;
case 4:cout < < "this constellation is " < <constellation[4];break;
case 5:cout < < "this constellation is " < <constellation[5];break;
case 6:cout < < "this constellation is " < <constellation[6];break;