Unresolved Externals Error

I have been learning for a few days now and today tried to combine a few things I have been learning to create a program. I have come across an issue that is way over my head for the time being and was hoping someone might be able to explain my error. Now please remember that this is snippets of a few days worth of learning compiled into one program so it's messy and not designed to be short and sweet, just to test myself so I'm just looking for a solution to the issue I'm facing. The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>

int main(void)
{
	using std::cout;
	using std::cin;

	int guess;
	int count = 0;

	cout << "Welcome to the psychic test. I am thinking of\na number between 1 and 10."
		<< "You have 5 guesses. What is it?\n";
	cout << "Please enter a number: ";
	cin >> guess;
	if (guess =! 4)
	{
		do
		{
	switch(guess)
	{
		default:
			cout << "You chose " << guess << ". That is not between 1 and 10.\n";
	case 1:
		cout << "1? I'm not so simple am I?\n\n";
		break;
	case 2:
		cout << "Hmm, nope. That would be too easy.\n\n";
		break;
	case 3:
		cout << "It may be a magic number, but it's not right this time.\n\n";
	case 5:
		cout << "Well this is embarrasing...\n\n";
	case 6:
		cout << "You really should get the hang of this.\n\n";
	case 7:
		cout << "Lucky for some, but not for you.\n\n";
	case 8:
		cout << "You'll have to try much harder.\n\n";
	case 9:
		cout << "I don't think you're getting this.\n\n";
	case 10:
		cout << "Nope, not this one.\n\n";
		}
	}
		while (count < 5);
	}
	else
		cout << "Congratulations! You did it!";
	return 0;
}


And the error I am recieving is:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
1>C:\Users\...\Debug\SwitchDefaults.exe : fatal error LNK1120: 1 unresolved externals
Last edited on
- line 15 probably was supposed to be if(guess != 4). Note the operator is !=, not =!. =! means something totally different.

- You're also missing breaks for cases 3-10.

- Also, you only get 'guess' from the user once at the start of your program. Since you don't get 'guess' inside the loop, every time that loop runs it will use the same guess.


As for the problem you're asking about:

You created the project as a "Win32" program and not a "Console" program. You need to either make a new project and create a console program, or you need to change the project settings to make it generate a console program and not a Win32 program.
Apologies for my ignorance but what is the difference and why did that cause the issue? I have been working with Console programs this whole time and haven't had errors. What caused this one to need to be Win32.

On a second note, thanks for the rundown of it's other issues but I am trying to figure that stuff on my own as a test to myself from the things I've learnt. Appreciate the help but I would have rather figured thos issues out on my own.

Once again, thank you.
Apologies for my ignorance but what is the difference and why did that cause the issue?


Console programs run in the console and have their IO through the console.

Win32 programs do not have a console, and instead are responsible for creating and maintaining their own window.

Console programs have the typical "main" function as their entry point.

Win32 programs don't have a main, but instead have a "WinMain" as the entry point (which also has different parameters and stuff).

The problem you're having is because the linker thinks there should be a WinMain because that's where it thinks the start of the program is. The error you're getting is basically the linker saying "hey, I can't find WinMain".

I have been working with Console programs this whole time and haven't had errors. What caused this one to need to be Win32.


You must have chosen the wrong option at the new project wizard.

Appreciate the help but I would have rather figured thos issues out on my own.


It honestly never occured to me that pointing out bugs would be a "spoiler", but I guess that's the case here, heh.

My apologies.
Yeah no worries, to be honest the only issue I didn't notice was the 'guess' was outside the loop. Mahor rookie error but would have been extremely apparant once I ran the program. But thanks for being helpful as hell!
Topic archived. No new replies allowed.