HELP! Weird error using functions.

closed account (y6DLy60M)
My code just gives me a long weird error code.


#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void presentValue(double, double, double);

int main()
{

double f, n, r;

cout << "Enter the future value. \n";
cout << "Value: \n";
cin >> f;
cout << "Enter how many years you want to let the money \n";
cout << " accumulate for. \n";
cout << "Years: \n";
cin >> n;
cout << "Enter a percentage for the rate. \n";
cout << "Rate: \n";
cin >> r;

cout << presentValue(f, n, r);


return 0;
}

void presentValue(double numF, double numN, double numR)
{
double p = ((numF)/(pow((1+numR),numN)));
cout<< " You need to deposit today \n";
cout<< " Present value: " << p << endl;
}

Right off the bat I can see that your function declaration of presentValue does not match up with your function definition. In your declaration, the parameters aren't really there, you just have the type, double, and no variable. Be sure to include the variables after the type in your declaration. Also, posting the error code or what it says would be helpful.
closed account (y6DLy60M)
Sorry this the error.

error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)

And I thought you didn't need the variable just its type.
Remove the cout << from in front of presentValue(double numF, double numN, double numR) The presentValue function doesn't return a value, so you can't really use "cout" with it. If you wanted to do something like that you would have to change void to another type such as int, and have the function return a value. However it looks like your function should handle the printing to the screen by itself, so you just need to call the function.
closed account (y6DLy60M)
Thank you very much. I forgot I had text within the function stating what I wanted to be said.
Topic archived. No new replies allowed.