I've written a program that finds the maximum of a function. I now want to change it a little so that instead of evaluating the function y=x^2-7x-18, the program will ask the user to input an equation and then evaluate that equation. I'm really not sure of how to do so. Can anyone help me out?
#include <iostream>
#include <cmath>
#include <cstdlib>
usingnamespace std;
int main()
{
int a, b, delta, x, y;
double max= -1.8 * pow(10, 308);
cout <<"Please enter the first number of the interval to be checked: " << endl;
cin >> a;
cout << "Please enter the last number of the interval to be checked: " << endl;
cin >> b;
delta= 1;
for(x = a; x <= b; x = x+delta)
{
y = pow(x, 2)-7*x-18;
if (y > max)
{
max = y;
}
else
{
delta= delta/2;
}
if (delta < pow( 10, -6))
{
break;
}
}
cout <<"The maximum over the interval from " << a <<" to " << b <<" is " << max;
return 0;
}