首页 文章

链接器麻烦再次[重复]

提问于
浏览
0

这个问题在这里已有答案:

嗨我一直试图找2小时试图找出这些错误的原因:

错误1错误LNK2019:函数___tmainCRTStartup中引用了未解析的外部符号_main
错误2错误LNK1120:1个未解析的外部

它在控制台设置上,我检查了子系统,它也在控制台上设置 . 我不知道出了什么问题,我也是新来的C所以慢慢解释(请)

#include <iostream>
#include <conio.h>
#include <string>
using namespace std;

int Range1, Range2, Guess, Midpoint, NumOfGuess;
string Selection;
bool GameQuit = false;

void MidpointReset()
{
    Midpoint = rand() % 31 + 0;
    Range1 = rand() % Midpoint + 0;
    Range2 = rand() % 31 + Midpoint;
}
void RangeReset()
{
    Range1 = rand() % Midpoint + Range1;
    Range2 = rand() % Range2 + Midpoint;
}
int Main()
{
    MidpointReset();
    while (GameQuit == false)
    {
        cout << "1. Show me the range" << endl
            << "2. I want to guess the number" << endl
            << "3. Quit" << endl
            << "4. Reset MidPoint"
            << "Enter your selection :" << endl;
        cin >> Selection;
        if (Selection == string("1"))
        {
            cout << "Between " << Range1 << " and " << Range2 << endl;
            RangeReset();
        }
        else if (Selection == string("2"))
        {

            cout << "Enter your guess:" << endl;
            cin >> Guess;
            NumOfGuess += 1;
            if (Guess == Midpoint)
            {
                cout << endl << "Right! It took you " << NumOfGuess << " trials!";
                GameQuit = true;
                break;
            }
        }
        else if (Selection == string("3"))
        {
            MidpointReset();
        }
        else if (Selection == string("4"))
        {
            cout << "Thanks for playing!";
            GameQuit = true;
            break;
        }
        else
        {
            cout << "Sorry " << Selection << "Is a invalid selection";
        }
    }
    cout << "Please press any key to exit...";
    _getch();
    return 0;
}

1 回答

  • 0

    小写事项 main()

    Main() 切换到 main() 以便找到入口点 .

    作为旁注:

    cout << "1. Show me the range" << endl
            << "2. I want to guess the number" << endl
            << "3. Quit" << endl
            << "4. Reset MidPoint"
            << "Enter your selection :" << endl;
    
    ....
    else if (Selection == string("3"))
    {
        MidpointReset();
    }
    else if (Selection == string("4"))
    {
        cout << "Thanks for playing!";
        GameQuit = true;
        break;
    }
    

    在帮助选择中交换3和4:4个退出,3重置中点 .

相关问题