Still there is an error.......Not Sure what the problem

Ok, I am still getting an error on this code.

1
2
Error	1	error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup	
Error	2	error LNK1120: 1 unresolved externals	


Here is my code

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
#include <iostream>
using namespace std;

int main()
{
	int number   = 0;
	int positive = 0;	//counter
	int negative = 0;	//counter

	//get a number
	cout << "Enter a positive or negative integer (enter 0 to end): ";
	cin >> number;

	while (number != 0)
	{
		//update counters
		if (number > 0)
			positive += 1;
		else
			negative += 1;
		//end if

		//get another number
		cout << "Enter another positive or negative integer (enter 0 to end): ";
		cin >> number;
	}//end while
	
	//display counters
	cout << endl;
	cout << "Total positive numbers: " << positive << endl;
	cout << "Total negative numbers: " << negative << endl;

	system("pause");
	return 0;
}	//end of main function


I am sure that the code is right. I need another set of eyes I am guessing.
Hi, I can see an immediate issue with your code. Not sure if it is the only one but at line 17, where your if statement starts, you do not have the brackets to close off the if statement. After if(number > 0), you need to press enter then place { followed by the closing bracket } after the positive += 1;. You need the same thing for the else statement. That seems to be possibly what the error at the top is stating. Of course that could just be one issue but I would try that out first.

If you have any other questions, check out my website www.simplecomputerapps.webs.com and post your programming questions on the forum here as well because I can see them better and more often to give you greater assistance. That site provides apps for free download and welcomes new suggestions as well as help in creating your own apps.
Last edited on
Your code is fine.

By the look of it your project is set up incorrectly. You need to make sure you are on a console application when you set it up and not a Windows application (in this case they are expecting a different form of the main function for Windows).

Try starting another project with console settings and pasting the code there.
(You may also just be able to go to Project - Properties - Linker - System and change the SubSystem to console, if you are on Visual Studio).
Last edited on
@Diana Magers

Actually, you only would need the curly brackets if you have more than one statement that needs to be run after the if statement. As maybe..
1
2
3
4
5
6
7
8
9
10
if (number > 0)
{
	positive ++;
       cout << "That was positive.." << endl;
}
	else
{
	negative ++;
       cout << "That was negative.." << endl;
}


I was able to compile and run your program, with no problems, what-so-ever, so I haven't the foggiest why it doesn't for you.
I would rewrite the main loop together with the previous prompt the following way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
	do
	{
		//get another number
		cout << "Enter another positive or negative integer (enter 0 to end): ";
		cin >> number;

		//update counters
		if ( number > 0 )
			positive++;
		else if ( number < 0 )
			negative++;
		//end if

	} while ( number != 0 );
I think you've made a Win32 Windows Application. Try making a new project but make an empty console program.
Topic archived. No new replies allowed.