Cannot convert float to float error

My program is giving me this error;

line 76 41 [Error] cannot convert 'float (*)(float, int)' to 'float' for argument '2' to 'float compound2y(int, float, double, int)'
line 77 43 [Error] cannot convert 'float (*)(float, int)' to 'float' for argument '2' to 'float compound10y(int, float, double, int)'

#include <iomanip>//needed for cout, cin and endl
#include <iostream>//needed to set width and precision
#include <cmath>//needed for math function
#include <windows.h>//needed for text and background colour changes
#include <string>

using namespace std;//avoids using std with cin, cout, endl etc.

float calc(float r, int n);
float compound2y(int p, float calc, double x, int initialdeposit);
float compound10y(int p, float calc, double y, int initialdeposit);

int main (int arc, char* argv[] )
{
system("COLOR F0"); //inverts colours, white background, black text

int p=15000;
float r=0.05;

HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);

double n=12, max, min;
int x=n*2;
int y=n*10;
int a,b;
float ci2y, ci10y;
char ans = 'Y' || 'y' || 'N' || 'n';
int initialdeposit;


do
{
cout << "enter a ";
cin >> a;
cout << "enter b ";
cin >> b;

cout << left << setw(20) << "\ninitial deposit ? ";
cout << left << setw(20) << "2 years ? ";
cout << left << setw(20) << "10 years" << endl;


if (a<50 && a<b)
{
min = a;
}

else if (b<=a && b<50)
{
min = b;
}

else if (50<=a && 50<=b)
{
min = 50;
}

if (a>50 && a>b)
{
max = a;
}

else if (b>=a && b>50)
{
max =b;
}

else if (50>=a && 50>=b)
{
max = 50;
}
ci2y=compound2y(p,calc,x,initialdeposit);
ci10y=compound10y(p,calc,y,initialdeposit);
initialdeposit=0.0;

for (int i=min; i<=max; i+=500)
{
initialdeposit=i;

cout << "\n" << left << setw(20) << setfill('e') << fixed << initialdeposit << " ? ";
cout << left << setw(20) << setfill('e') << fixed << ci2y << " ? ";
cout << left << setw(20) << setfill('e') << fixed << ci10y;
}

cout << "\nDo you want to try another interval? (Y/N) ";
cin >> ans;

if (ans == 'N' || ans == 'n')//condition if user answers no to question
{
cin.get();//end program
}

else if (ans != 'Y' && ans !='y' && ans != 'N' && ans != 'n')//condition if user enters a character
//that is not Y or N. Else if because if condition already used to end
//program if user answers no, and do while loop condition for user
//answers yes.
{
//display error message if user enters an invalid character
SetConsoleTextAttribute(hConsole,244);//changes error message text
//to red.
cout << "\nInvalid input. Please answer Y / N. ";//error message.
//request new input.
SetConsoleTextAttribute(hConsole,240);//changes answer text to black
cin >> ans;//new answer
}
}
while ((ans == 'Y') || (ans == 'y') && (initialdeposit<=max));

//allow user to see result before ending
cout << "\n\nPress enter to end this program" << std::endl;
cin.get();
}

float calc(float r, int n)
{
return (1+r/n);
}

float compound2y(int p, float calc, double x, int initialdeposit)
{
return ((p-initialdeposit)*pow(calc, x)-p);
}

float compound10y(int p, float calc, double y, int initialdeposit)
{
return ((p-initialdeposit)*pow(calc,y)-p);
}
Code tags, please!

1
2
3
4
5
6
7
float calc(float, int);
float compound2y(int, float, double, int);
float compound10y(int, float, double, int);

// 
ci2y=compound2y( p, calc, x, initialdeposit );
ci10y=compound10y( p, calc, y, initialdeposit );

You call these functions with a name of a function as a parameter, but these functions do not expect a pointer to function, they expect a float.

Perhaps:
1
2
ci2y=compound2y( p, calc(3.14, 42), x, initialdeposit );
ci10y=compound10y( p, calc(2.7, 7), y, initialdeposit );

That worked, i used calc(r,n), thank you!!
Topic archived. No new replies allowed.