如何修复“在(cout)之前预期的初始化程序”和“在'else'之前预期的不合格ID”?

时间:2019-07-24 14:22:58

标签: c++

我正在使用c ++创建文本冒险,但是有两个错误。一个声明在“ else”语句(第92行)之前期望使用不合格的ID,而另一个声明在输出之前期望使用初始化器。 (第68行)。它们以ERRORHERE标记。 对于“其他”问题,我尝试添加和删除括号。 对于cout问题,我什至不知道从哪里开始。 链接到OnlineGDB代码:https://onlinegdb.com/rJQaQgLGH

#include <iostream>
using namespace std;
enum Response {Yes = 1, No = 2};
enum FirstDoor {Left = 1, Right = 2};
enum LightLamp {Oui = 1, Non = 2};
enum GoblinFight {Attack = 1, Run = 2};
enum LizardBattle {Sword = 1, Bow = 2};
enum SelectArtifact {Scroll = 1, Box = 2};
enum Healing {Ja = 1, Nei = 2};
enum DangerTurnBack {Danger = 1, TurnBack = 2};
enum EscapeContinue {Escape = 1, Continue = 2};
enum TunnelLeftForward {TunnelLeft = 1, Forward = 2};
enum TUnnelTurnBack {TunnelYes = 1, TunnelNo = 2};
int main()
{
    int UInput = Yes;
    cout<<"Hello there.\n";
    cout<<"Would you like to play a game?\n";
    cout<<"Please type in 1 for Yes, 2 for No.\n";
    cin>>UInput;
    if (UInput == Yes){
        int FDUInput = Left;
        cout<<"This game is a text-based adventure.\n";
        cout<<"You start out in a dungeon. Your primary objective is to navigate the maze, kill the boss, and escape.\n";
        cout<<"You are in a damp, dark room. There are two doors, to the left and to the right. Which way do you want to go?\n";
        cout<<"Please type 1 for Left, 2 for Right.\n";
        cin>>FDUInput;
        if (FDUInput == Left){
            int LLUInput = Yes;
            cout<<"You arrive in a dark corridor. You see a lamp and a match on the ground. Would you like to light the lamp?\n";
            cout<<"Press 1 for Yes, 2 for No.\n";
            cin>> LLUInput;
                if (LLUInput == Oui){
                    int LBUInput = Sword;
                    cout<<"The lamp is lit and you look up just in time to see a small-ish lizard. What would you like to do?\n";
                    cout<<"Press 1 to swing your sword, and press 2 to shoot your bow\n";
                    if (LBUInput == Sword){
                        cout<<"The lizard was cut in half but managed to scratch you\n";
                        cout<<"Would you like to heal yourself?\n";
                        int HUInput = Ja;
                        if (HUInput == Ja)  {
                            cout<<"You are all healed. You see two doors at the end of the corridor, one says 'Danger' and the other says 'Turn Back'.\n";
                            //continue
                        }
                        else{
                            int DTBUInput = Danger;
                            cout<<"You are slowly bleeding as you walk towards two doors at the end of the corridor, one says 'Danger' and the other says'Turn Back'.\n";
                            cout<<"Not much choice... Oh well. Which way do you go? Press 1 for 'Danger' and 2 for 'Turn Back'.\n";
                            cin>> DTBUInput;
                            if (DTBUInput == Danger){
                                cout<<"You almost stumble into a spike trap, only to fall backwards as you frantically swing your arms.\n";
                                cout<<"You look around the room and take a mental note of all the traps that you can see.\n";
                                //continue

                            }
                    }
                }
                        else{
                            cout<<"'You should have turned back...' a raspy voice says. You try to run away but an invisible hand grabs you.\n";
                            cout<<"GAME OVER\n";
                            cout<<"Thank you for playing this game.\n";
                        }
                    }
                }
                else{
                    int TLFUInput = Left,
                    cout<<"The lizard was shot in the head. As you look around, you spot a small tunnel.\n"; //ERRORHERE
                    cout<<"You walk through the tunnel when the lamp goes out. You sense another path to the left.\n";
                    cout<<"Which way do you go? Left(1) or Forward(2)?\n";
                    cin>> TLFUInput;
                    if (TLFUInput == Left){
                        int TTBInput = Yes;
                        cout<<"The tunnel slowly opens outwards and you see a treasure room with a big hulking figure in it.\n";
                        cout<<"Would you like to turn back? Please press 1 for Yes and 2 for No.\n";
                        if (TTBInput == Yes){

                        } 
                    }
                    else{
                        cout<<"The tunnel continues forward for a long while. When you finally go out, you see ";
                    }
                    //continue
                }
}
            else{
                cout<<"You were ambushed by a horde of skeletons and overwhelmed.\n";
                cout<<"GAME OVER\n";
                cout<<"Thank you for playing this game.\n";
            }
    }
    else{ //ERRORHERE
        int GFUInput = 1;
        cout<<"You find yourself in a sunlit room, and a small goblin horde attacks you. What would you like to do?\n";
        cout<<"Please select 1 to attack, and 2 to run\n";
        cin>> GFUInput;
            if (GFUInput == Attack){
                cout<<"The goblins overwhelmed you.\n";
                cout<<"GAME OVER\n";
                cout<<"Thank you for playing this game.\n";
            }
            else {
                int LLUInput = Oui;
                cout<<"The goblins tried to chase you but failed. You got away safely, but now you are in a dark corridor.";
                cout<<"You arrive in a dark corridor. You see a lamp and a match on the ground. Would you like to light the lamp?\n";
            cout<<"Press 1 for Yes, 2 for No.\n";
            cin>> LLUInput;
                if (LLUInput == Oui){
                    int SAUInput = Scroll;
                    cout<<"The lamp is lit and you look around and spot a door.\n";
                    cout<<"You walk through the door and you see a scroll and a jewelry box. Both are rare artifacts. Which do you take?\n";
                    cout<<"Press 1 for the scroll and 2 for the box.\n";
                    cin>> SAUInput;
                    if (SAUInput == Scroll){
                        int LBUInput = Sword;
                        cout<<"You decide to read it once you've escaped the dungeon, but when you look up, an army of skeletons has appeared.\n";
                        cout<<"Would you like to use your sword (press 1) or your bow (press 2)?\n";
                        cin>> LBUInput;
                        if (LBUInput == Sword){
                            cout<<"You frantically swing your sword and somehow manage to fend off the skeletons.\n";
                            //continue
                        }
                        else {
                            cout<<"The bow was not fast enough and the skeletons defeated you.\n";
                            cout<<"GAME OVER\n";
                            cout<<"Thank you for playing this game.\n";
                        }
                    }
                    else{
                        int CEUInput = Escape;
                        cout<<"You open the box and find a letter and a map.\n";
                        cout<<"You open the letter and it reads: 'Escape while you can. There is no hope for you here.' Would you like to escape or continue?\n";
                        cin>> CEUInput;
                        //continue
                    }
                }
                else{
                    cout<<"You were fatally injured by a lizard's claws before you could react.\n";
                    cout<<"GAME OVER\n";
                    cout<<"Thank you for playing this game.\n";
                }
            }


        }
}
else {
    cout<<"Thank you for trying out this program.\n";
}
return 0;











    ERROR MESSAGES:
main.cpp:68:29: error: expected initializer before ‘<<’ token
                         cout<<"The lizard was shot in the head. As you look around, you spot a small tunnel.\n";
                             ^~
main.cpp: At global scope:
main.cpp:92:9: error: expected unqualified-id before ‘else’
         else{
         ^~~~

0 个答案:

没有答案