首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

找错解决方法

2012-03-26 
找错我想返回switch()大家看看怎么去做intchinese_constellation(){stringconstellation[12]{ 猴 , 鸡

找错
我想返回   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;


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 y <=11 ? y:-1;

热点排行