Logo 
Search:

C++ Programming Forum

Ask Question   UnAnswered
Home » Forum » C++ Programming       RSS Feeds

What is wrong with my code?

  Asked By: Eugene    Date: Jan 05    Category: C++ Programming    Views: 402
  

Help me please! i keep on seeing this error!

cannot convert `double' to `double*' for argument `1' to `double get_fx(double*, int, double, double, double)'

here is my code.
please help me fix it

#include <iostream>
#include <math.h>
#include <Windows.h>

using namespace std;

int input_pol(double coef[],int& Pow);
double get_fx(double coef[],int Pow,double l,double x,double fx);

double falsi(double*, double);

const int MAX = 1000;


int main()
{

double coef[1000];
double xnew[MAX], xplus[MAX], xminus[MAX];
int imax, Pow;

input_pol(coef,Pow);




cout << endl;
cout << "Enter first guess: ";
cin >> xplus[0];
cout << endl;
cout << "Enter Second guess: ";
cin >> xminus[0];
cout << endl;
cout << "Set maximum iteration: ";
cin >> imax;

for(int i = 0; i < imax; i++)
{
xnew[i] = falsi(xplus[i], xminus[i]);

if(get_fx(xnew[i])> 0)
{
xplus[i+1] = xnew[i];
xminus[i+1]=xminus[i];
}
else
{
xminus[i+1] = xnew[i];
xplus[i+1]=xplus[i];
}
}
cout << endl << endl;
for(int i = 0; i < imax; i++)
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(20);
cout << xnew[i] << endl;
}

cout << endl << endl << endl;
cout << "The Approximate root is: ";

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(20);
cout << endl << endl << xnew[imax - 1];

cin.get();
cin.get();

return 0;
}
int input_pol(double coef[],int& Pow)
{
cout<<"Enter the highest degree in the polynomial: ";
cin>>Pow;
cout<<endl;
for(int i=Pow;i>=0;i--)
{
cout<<"Enter the coefficient of each term with thier corresponding sign."<<endl;
cout<<i+1<<" term: ";
cin>>coef[i];
cout<<coef[i]<<"x^"<<i<<endl;
}
}
double get_fx(double coef[],int Pow,double l,double x,double fx)
{

for(int i=Pow;i>=0;i--)
{
l+=(coef[i]*pow(x,i));
fx=l;
}
return fx;
}

double falsi(double* xp, double xm)
{
return xp - get_fx(xp) *(xp - xm)/(get_fx(xp) -get_fx(xm));
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on What is wrong with my code? Or get search suggestion and latest updates.




Tagged: