I am trying to experiment with C++ to make the command prompt function like MatLab or Octave.
This is a practice file I've been doing so I could pass functions as parameters to other functions.
My problem is with this function call found in line 36
compute(gset[function-1], input);
This is supposed to be correct according to what I know and according to another program that uses this similar snippet with the difference being the implementation of the function that I am passing a function to is in a separate header file.
So far I only have one compilation error and if somebody can help me with this, I'd truly be grateful.
#include <iostream>
//#include <math.h>
//#include <iomanip>
//#include <stdio.h>
using namespace std;
double f1(double x)
{
return(2*x);
}
double f2(double x)
{
return(x*x);
}
double compute(double f(double x), double i)
{
double answer;
answer = f(i);
return (answer);
}
int main()
{
double input, function, ans;
double (*gset[])(double)={f1,f2};
Input:
cout << "Input Please: ";
cin >> input;
cout << "Function Please: ";
cin >> function;
ans = compute(gset[function-1], input);
cout << ans;
goto Input;
}