为什么会出现看似随机的语法错误?

时间:2019-07-08 02:14:53

标签: c++ visual-studio-code c++17

我正在尝试在Visual Studio Code上创建一个名为Bulls and Cows的简单游戏。到目前为止,该游戏还很不完整,但是我一直在编译程序,它返回的看似随机的错误对我来说没有任何意义。也许有人可以解释为什么编译器返回这些错误。


    #include <iostream>
    using namespace std;


    class Game 
    {
        public:
            void StartGame();
        private:
            void EasyMode();
            void ModerateMode();
            void HardMode();
            string hidded_word;
            int bulls;
            int cows;
    };


    void Game::StartGame()
    {
        cout << "***********WELCOME TO BULLS AND COWS**************" << endl
        cout << "          Choose your difficulty" << endl << endl;
        cout << "    Easy       Moderate        Hard" << endl << endl;
        string difficulty;
        cin >> difficulty;
        cout << endl;

        if (difficulty == "Easy" || difficulty == "easy")
            {
                EasyMode();
            }
         else if(difficulty == "Moderate" || difficulty == "moderate")  
            {
                ModerateMode();
            }
          else(difficulty == "Hard" || difficulty == "hard")  
            {
                HardMode();
            }
    }


    void Game::EasyMode()
    {
     cout << "Easy mode";
    }

    int main()
    {
        cout << endl << endl;
        cout << "Hello Worldy";
    }

编译器返回以下错误:

TestBullCow.cpp(38): error C2059: syntax error: ';'
TestBullCow.cpp(40): error C2059: syntax error: '}'
TestBullCow.cpp(40): error C2143: syntax error: missing ';' before '}'
TestBullCow.cpp(44): error C2143: syntax error: missing ';' before '{'
TestBullCow.cpp(44): error C2447: '{': missing function header (old-style 
 formal list?)

0 个答案:

没有答案