调用函数时找不到标识符?

Identifier not found when im calling a function?

所以我正在制作一个数学游戏,但是当我尝试在一个函数中调用一个函数时,正如您在我的代码中看到的那样,它显示 'Start':找不到标识符,即使我将函数放在我尝试调用的函数之上,但它仍然说找不到标识符,有什么帮助吗?

void Inventory()
    {
        char inv;
        cout << "Do you wan't to open your inventory?" << endl;
        cout << "1.Yes 2.No." << endl;
        cin >> inv;
        switch (inv) {
        case '1':
            cout << "You opened your inventory" << endl;
            break;
        case '2':
            cout << "Returning to main menu" << endl;
            Sleep(1000);
            Start();
            break;

        }
    }
}

这是我正在调用的函数。

void Start()
    {
        points = 10;
        system("color b");
        cout << R"(
             __  __          _____ _   _   __  __ ______ _   _ _    _ 
            |  \/  |   /\   |_   _| \ | | |  \/  |  ____| \ | | |  | |
            | \  / |  /  \    | | |  \| | | \  / | |__  |  \| | |  | |
            | |\/| | / /\ \   | | | . ` | | |\/| |  __| | . ` | |  | |
            | |  | |/ ____ \ _| |_| |\  | | |  | | |____| |\  | |__| |
            |_|  |_/_/    \_\_____|_| \_| |_|  |_|______|_| \_|\____/ 

                                      PLEASE SELECT AN OPTION!

    )";
        system("color b");
        int shop;
        int shopitems;
        char inventory;

        cout << "   You have " << points << " points!" << endl;
        cout << "   [1] Play" << endl;
        cout << "   [2] Inventory" << endl;
        cout << "   [3] Shop" << endl;
        cout << "   [4] Exit" << endl;
        printf("   >> ");
        cin >> inventory;

        switch (inventory) {
            case '1':
                PlayGame();
                break;
            case '2':
                Inventory();
                break;
            case '3':
                printf("3");
                break;
            case '4':
                printf("4");
                break;
                return;
        }
    }
    ```

首先声明函数

void Inventory();
void Start();

然后定义它们。

就我个人而言,我不确定您为什么在 if/else 情况下使用 case。然后你不需要休息 - 它会自动 returns 开始。至于函数,您可以在 main 函数之前声明函数,也可以在 main 之前创建函数原型,然后在之后调用函数(我个人的偏好)。我喜欢在 main 中开始跟踪我的代码,所以更喜欢 main 之前的原型,之后的函数。

您可能想在此处查看更多信息:http://www.cplusplus.com/doc/tutorial/ 或使用 C++ 播放列表构建游戏以学习语言结构。