您好我尝试了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;
}
答案 0 :(得分: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个重置中点。