Help with C++ functions please help!

I am tying to display how many numbers the user entered and my program is like this:

#include <iostream>
using namespace std;
void getInput(double);
//**************** main function ****************************
int 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 0;
}


//***************** count function *********************
void getInput(double count)
{
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;

}

The only problem is when I compile it, it tells me the getInput() has no matching function.

Please Help!
I'm really tired, so I'm sorry if my answer is wrong, but it looks like you define getInput() to pass a function, but when you call the function, you don't pass anything to it. IOW, you have to put count in the parenthesis when you call the function in main(). You are going have to declare count as a variable, too. You are also missing a "{" in your if statement.
I did what you said and put count between the parenthesis but now it says the error is Invalid operands to binary expression

What should I do now?
which is the editor you are using ?
getInput() function doesn't need any parameters but must return the 'int' type variable 'count'

1
2
//***************** count function *********************
int getInput()


 
int count = 0;


1
2
//return counting result
return count;


And please use [ code ] [/code ] tags next time.
Last edited on
Thanks for all your help but now it says "No matching function for call to 'getInput'

By the way I am using Xcode.
Did you change getInput at the top to an int?
yes, now it displays this:

//***************** count function *********************
int getInput()
{
double number; //hold number entered by the user
int 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;

}
Topic archived. No new replies allowed.