Compile problem

Hi I cant get my program compile, it is suppose to display the negative numbers entered by the user

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

//**************** main function ****************************
void main()
{
   	cout << "This program count how many negative numbers you enter. \nThere will be three sections. \nEnter 0 to end a section." <<endl<<endl;

	for (int i=0; i<3; i++)
	{
		cout << "\n************ SECTION " << i+1 << "**************"<<endl;
		cout << "\nYou have entered " << getInput() << " negative numbers so far."<<endl;
		cout << "**************************"<<endl<<endl;

	}

    return;
}


//***************** count function *********************
int getInput()
{
    double number;	//hold number entered by the user
	count=0;

	//get input
	do
	{
	cout << "Enter a number: ";
	cin >> number;

		//count positive number
	if (number < 0)
		count ++;
	} while (number !=0);

	//return counting result
	return count;

}
line 25 the variable has no type. I think you may have meant int count = 0;
thanks I missed that, I don't what else is wrong it still wont compile
Try doing int main(int argc, char **argv) instead of void main() and then change return; to return 0;
And you will also need a function prototype: int getInput();
This is because you define the function after main and main does not "know" about it. So just put that prototype somewhere at the top of your file above int main.
The prototype allows you to define the function after main.
Last edited on
thanks I missed that, I don't what else is wrong it still wont compile

You know, your compiler will be outputting handy error messages to explain to you what the errors are, and on which lines they occur.

If the people who wrote your compiler decided that it would be helpful for it to tell you that information, what made you decide that it wouldn't be helpful to tell us the same information?
Last edited on
Thanks for help kevin I will try that also, and as for the errors that I receive in the compiler are,

6 C:\Users\2.cpp `main' must return `int'

C:\Users\2.cpp In function `int main(...)':

12 C:\Users\2.cpp `getInput' undeclared (first use this function)

(Each undeclared identifier is reported only once for each function it appears in.)

17 C:\Users\2.cpp return-statement with no value, in function returning 'int'

C:\Users\2.cpp In function `int getInput()':

23 C:\Users\2.cpp `int getInput()' used prior to declaration

25 C:\Users\2.cpp overloaded function with no contextual type information

35 C:\Users\2.cpp no post-increment operator for type

39 C:\Users\Desktop\2.cpp cannot resolve overloaded function `count' based on conversion to type `int'
All those errors should disappear after you make the changes I suggested. Let us know if you get any other errors after making those changes.
thanks for the help! finally got it to work.
Topic archived. No new replies allowed.