| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 494 人关注过本帖
标题:这有什么错误啊,说返回类型没有被定义
只看楼主 加入收藏
找回信仰
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-3-7
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
这有什么错误啊,说返回类型没有被定义
#include<iostream>
using namespace std;
struct bop
{
       char fullname[20];
       char title[20];
       char bopname[20];
       int preference;
}
int main()
{
    bop arry[5];
    bop arry[1]={Wimp Macho,Wimp Macho,gou,1};
    bop arry[2]={Raki Rhodes,Junior Programmer,mao,2};
    bop arry[3]={Hoppy Hipman,MIPS,yu,3};
    bop arry[4]={Celia laiter,Analyst Trainee,xiong,2};
    bop arry[5]={Ydsha Sjfdl,DJFA alf,zhu,1};
   
    cout<<"Benevolent Order of Programmers Report\n";
    cout<<"a. display by name        b. display by title\n";
    cout<<"c. display by bopname     d. display by preference\n";
    cout<<"q. auit";
    cout<<"Enter your choice:";
    char ch;
    cin.get(ch);
   
    int i;
    for(i=1;i<=5;i++)
    {
       switch(ch)
       {
           case'a':cout<<arry[i].fullname<<"\n";break;
           case'b':cout<<arry[i].title<<"\n";break;
           case'c':cout<<arry[i].bopname<<"\n";break;
           case'd':if(arry[i].preference=='1'
                     cout<<arry[i].fullname<<"\n";break;
                     else if(arry[i].preference=='2'
                     cout<<arry[i].title<<"\n";break;
                     else if(arry[i].preference=='3'
                     cout<<arry[i].bopname<<"\n";break;
           case'q':cout<<"quit\n";break;
           defaut:cout"it is wrong";
       }
     }
   system("pause");
   return 0:
}
还有如果要在switch之后再次回到cin.get()也就是说可以多次输入输出怎么办
搜索更多相关主题的帖子: namespace include Junior title 
2013-03-09 15:30
锋了
Rank: 7Rank: 7Rank: 7
来 自:向日葵幼儿园
等 级:黑侠
威 望:2
帖 子:306
专家分:586
注 册:2012-10-27
收藏
得分:10 
想循环输入你可以吧switch(ch)改为switch(cin.getch(ch)),把break改为continue
这里if(arry[i].preference=='1'少了个括号
这里应该加大括号,不然else就不执行了(我想是的,你试试看吧)
if(arry[i].preference=='1')
                     {cout<<arry[i].fullname<<"\n";break;}
                     else if(arry[i].preference=='2'
                     {cout<<arry[i].title<<"\n";break;}
}                     else if(arry[i].preference=='3'
                     cout<<arry[i].bopname<<"\n";break;
2013-03-09 15:58
rjsp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:528
帖 子:9031
专家分:54061
注 册:2011-1-18
收藏
得分:10 
除非必要,几无改动,仅是修正你的错误
程序代码:
#include <iostream>
using namespace std;

struct bop
{
    char fullname[20];
    char title[20];
    char bopname[20];
    int preference;
};

int main()
{
    bop arry[5] = { { "Wimp Macho",   "Wimp Macho",        "gou",   1 }
                  , { "Raki Rhodes",  "Junior Programmer", "mao",   2 }
                  , { "Hoppy Hipman", "MIPS",              "yu",    3 }
                  , { "Celia laiter", "Analyst Trainee",   "xiong", 2 }
                  , { "Ydsha Sjfdl",  "DJFA alf",          "zhu",   1 } };

    cout << "Benevolent Order of Programmers Report\n"
            "a. display by name        b. display by title\n"
            "c. display by bopname     d. display by preference\n"
            "q. quit\n"
            "Enter your choice:" << flush;

    for( char ch; cin>>ch; )
    {
        if( ch == 'q' )
        {
            cout << "quit" << endl;
            break;
        }
        if( ch<'a' || ch>'d' )
        {
            cout << "it is wrong" << endl;
            continue;
        }

        for( int i=0; i<5; ++i )
        {
            const bop& ref = arry[i];

            switch( ch )
            {
            case 'a':
                cout << ref.fullname << endl;
                break;
            case 'b':
                cout << ref.title << endl;
                break;
            case 'c':
                cout << ref.bopname << endl;
                break;
            case 'd':
                if( ref.preference == 1 )
                    cout << ref.fullname << endl;
                else if( ref.preference == 2 )
                    cout << ref.title << endl;
                else if( ref.preference == 3 )
                    cout << ref.bopname << endl;
                break;
            }
        }
    }

    return 0;
}

2013-03-09 16:09
快速回复:这有什么错误啊,说返回类型没有被定义
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017705 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved