【已解决】新手C++学习者的一点问题
Tofloor
poster avatar
Emmmmmmmm
deepin
2019-02-19 03:52
Author
本帖最后由 Emmmmmmmm 于 2019-2-18 20:14 编辑

源程序部分:
    int choose(string a)
    {
        int x;
        if(a=="end")
        {
            x=0;
        }
        else(a=="jia")
        {
            x=1;
        }
        else(a=="jian")
        {
            x=2;
        }
        else(a=="cheng")
        {
            x=3;
        }
        else(a=="shu")
        {
            x=4;
        }
        else
        {
            x=666;
        }
        return x;
    }


不知道为什么编辑器里粘贴来是有颜色的2333

显示错误信息:
1.cpp:15:9: error: expected ‘;’ before ‘{’ token
         {
         ^
1.cpp:18:9: error: ‘else’ without a previous ‘if’
         else(a=="jian")
         ^~~~
1.cpp:19:9: error: expected ‘;’ before ‘{’ token
         {
         ^
1.cpp:22:9: error: ‘else’ without a previous ‘if’
         else(a=="cheng")
         ^~~~
1.cpp:23:9: error: expected ‘;’ before ‘{’ token
         {
         ^
1.cpp:26:9: error: ‘else’ without a previous ‘if’
         else(a=="shu")
         ^~~~
1.cpp:27:9: error: expected ‘;’ before ‘{’ token
         {
         ^
1.cpp:30:9: error: ‘else’ without a previous ‘if’
         else
         ^~~~





Reply Favorite View the author
All Replies
avatar
nbxwj
deepin
2019-02-19 04:08
#1
else后再加上 if
Reply View the author
Comments
Emmmmmmmm
2019-02-19 04:13
感谢
avatar
魔法师
deepin
2019-02-19 05:36
#2
老哥基础不过关啊,不过有很多坑得踩踩,掉坑里再爬出来就等于成长。
Reply View the author
avatar
Ligocut光剪视频剪辑软件
deepin
Backbone of ecological co-construction group
2019-02-19 07:33
#3
else if      
Reply View the author
avatar
让我康康
deepin
2019-02-19 16:34
#4
新手推荐C++ prime plus
Reply View the author