
February 4th, 2013, 08:59 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 22 m 41 sec
Reputation Power: 0
|
|
Syntax errors - Initialization
I am trying to compile the following C++ program using CodeBlocks:
#include<iostream>
using namespace std;
double function f(double x)
{
return 1 + x*(24 + x*(-50 + x*(35 + x*(-140 + x))));
};
double function fdash(double x)
{
return 24 + x*(-100 + x*(105 + x*(-40 + 5*x)));
};
double function Newton(double x0,double tol)
{
double x = x0; double incr = 1000;
while (abs(incr) > tol)
{
incr = f(x)/fdash(x);
x = x - incr;
} ;
return x;
};
int main()
{
double x0 = 0.2;
cout << Newton(x0,0.00001)<< endl;
return 0;
};
but get the following error messages:
line 4 error: expected initializer before 'f'
line 8 error: expected initializer before 'fdash'
line 12 error: expected initializer before 'Newton'
Can anybody help? What am I doing wrong?
|