The error is: F:\C ++ Numerical Methods\Newton_Raphson.cpp(199) : fatal error C1004: unexpected end of file found

#include <cmath>
#include <iostream> 
using namespace std;

double F ( double X )
{  
	
  return pow ( X, 4) - 9*pow ( X, 3 ) - 2*pow (X, 2) + 120*X - 130;
}

double DF (double X)
{
	return 4*pow (X, 3) - 27*pow (X, 2) - 4*X + 120;
}

double DDF (double X)
{
	return 12*pow (X, 2) - 54*X -4;
}

int main()
{
  char ANSWER;
  int TALLY;
  double X, XL, XR, XS, Y, YL, YR;
  double XB, XND, STEPSIZE;
  double XO, XN, FX, DFX, DDFX;
  double INT_ACC, ROOT_ACC, TOO_BIG, TOO_SMALL;

  ANSWER = 'Y';
  TALLY = 0;
  
  XL = 0.0;
  XR = 0.0;
  XS = 0.0;

  X = 0.0;
  Y = 0.0;
  YL = 0.0;
  YR = 0.0;

  XB = 0.0;
  XND = 0.0;
  STEPSIZE = 0.0;

  XO = 0.0;
  XN = 0.0;
  FX = 0.0;
  DFX = 0.0;
  DDFX = 0.0;

  INT_ACC = 0.0;
  ROOT_ACC = 0.0;
  TOO_BIG = 0.0;
  TOO_SMALL = 0.0;

  
  while (ANSWER == 'Y');

  cout<<"What is the left-most interval endpoint? ";
  cin>> XB;

  cout<<"What is the right-most interval endpoint? ";
  cin>> XND;

  cout<<"What is the desired step-size for function evaluation? ";
  cin>> STEPSIZE;

  cout<<"How close can the approximate root be to the true root to invoke root-finding? ";
  cin>> INT_ACC;

  cout<<"What is the size limit on the 2nd derivative? ";
  cin>> TOO_BIG;

  cout<<"How close can the 1st derivative get to zero? ";
  cin>> TOO_SMALL;

  cout<<"What is the desired accuracy for root-finding? ";
  cin>> ROOT_ACC;


  XL = XB;

  while ( true ) {
    YL = F ( XL );
    XR = XL + STEPSIZE;
    YR = F ( XR );

    if ( YL * YR > 0 ) {
      if ( XR >= XND ) goto end;

      XL = XR;
      YL = YR;
    }

    if ( YL * YR == 0 ) {
      if ( YL == 0.0 ) {
        cout<<"This is a root. "<< XL<<endl;

        if ( XR >= XND ) goto end;

        XL = XR;
      }
      else {
        cout<<"This is a root. "<< XR<<endl;

        if ( XR >= XND ) goto end;

        XL = XR + STEPSIZE;
      }
    }//end if

    if ( YL * YR < 0 ) {
      XS = XR;

      while ( true ) {
        X = ( XL + XR ) / 2;
        Y = F ( X );

        if ( YL * Y > 0 ) {
          XL = X;
          YL = Y;
        }

        if ( YL * Y == 0 ) {
          cout<<"This is a root. "<< X<<endl;

          XR = X;
          YR = Y;
        }

        if ( YL * Y < 0 ) {
          XR = X;
          YR = Y;
        }

        if ( fabs(XR - XL) < INT_ACC) {
         cout<<"This interval contains a root at "<< XL <<','<< XR<<endl;
	
		  XO = (XL + XR)/2.0;

		  TALLY = 1;

		while ( true ) {
		  FX = F(XO);
		  DFX = DF(XO);
		  DDFX= DDF(XO);

		  if (fabs(DDFX)>= TOO_BIG) {

	                cout<<"Condition 1 FAILS: 2nd derivative too large. ";

		  }
		  break;
		}//end of while

		if (fabs(DFX) <= TOO_SMALL) {

		cout<<"Condition 2 FAILS: 1st derivative too close to zero. ";

			}
		}//end if

		if (TALLY > 15) {
		cout<<"Slow convergence. Possible infinite loop.";

		}
	  }//end while

			XN = XO - (FX/DFX);

			if (fabs(XN-XO) < ROOT_ACC) {
				cout<<"The root is: "<<XN<<endl;
			}

			else

				XO = XN;
			TALLY = TALLY + 1;
			break;

		}
  


			XL = XS;

          if ( XL >= XND ) goto end;

          break;

		  cout<<"Would you like to run the program again? (Y or N)";
		  cin>>ANSWER;
     

end:
  return 0;
}

Perhaps you could help us a bit by explaining the error.

When I've encountered this error before it was generally when I was removing debugging code and erased one too many curly braces. To track it down I'd start commenting out whole chunks of the program until I got it to compile and then start adding small sections back one at a time, making sure I had matching opening and ending braces with each add back.

From the error number I'd say you are using one of the Microsoft compilers. If that is true you can easily and quickly find out the missing { or } by putting the cursor on one of the brackets and hitting Ctrl+{ or Ctrl+}. This doesn't work so well if you have { or } in quotes

VI and probably some other compiler IDEs also have similar macros to help find missing or matching brackets, braces and parentheses.

Another possibility: If you are using Microsoft compilers with precompiled headers then you have to include stdafx.h as the very first include file. If you don't have stdafx.h then disable precompiled headers. How to do that depends on the compiler version you are using.

#include "stdafx.h"
// other stuff here

>>From the error number I'd say you are using one of the Microsoft compilers. If that is true you can easily and quickly find out the missing { or } by putting the cursor on one of the brackets and hitting Ctrl+{ or Ctrl+}. This doesn't work so well if you have { or } in quotes

Cool! Now if I can only remember that the next time I need it!

You are missing a closing } to one of your while loops. But you'll never ever get past the line:

while (ANSWER == 'Y');

This is an endless loop created by the ; at the end of the (ANSWER == 'Y');

The error is: F:\C ++ Numerical Methods\Newton_Raphson.cpp(199) : fatal error C1004: unexpected end of file found

#include <cmath>
#include <iostream> 
using namespace std;

double F ( double X )
{  
	
  return pow ( X, 4) - 9*pow ( X, 3 ) - 2*pow (X, 2) + 120*X - 130;
}

double DF (double X)
{
	return 4*pow (X, 3) - 27*pow (X, 2) - 4*X + 120;
}

double DDF (double X)
{
	return 12*pow (X, 2) - 54*X -4;
}

int main()
{
  char ANSWER;
  int TALLY;
  double X, XL, XR, XS, Y, YL, YR;
  double XB, XND, STEPSIZE;
  double XO, XN, FX, DFX, DDFX;
  double INT_ACC, ROOT_ACC, TOO_BIG, TOO_SMALL;

  ANSWER = 'Y';
  TALLY = 0;
  
  XL = 0.0;
  XR = 0.0;
  XS = 0.0;

  X = 0.0;
  Y = 0.0;
  YL = 0.0;
  YR = 0.0;

  XB = 0.0;
  XND = 0.0;
  STEPSIZE = 0.0;

  XO = 0.0;
  XN = 0.0;
  FX = 0.0;
  DFX = 0.0;
  DDFX = 0.0;

  INT_ACC = 0.0;
  ROOT_ACC = 0.0;
  TOO_BIG = 0.0;
  TOO_SMALL = 0.0;

  
  while (ANSWER == 'Y');

  cout<<"What is the left-most interval endpoint? ";
  cin>> XB;

  cout<<"What is the right-most interval endpoint? ";
  cin>> XND;

  cout<<"What is the desired step-size for function evaluation? ";
  cin>> STEPSIZE;

  cout<<"How close can the approximate root be to the true root to invoke root-finding? ";
  cin>> INT_ACC;

  cout<<"What is the size limit on the 2nd derivative? ";
  cin>> TOO_BIG;

  cout<<"How close can the 1st derivative get to zero? ";
  cin>> TOO_SMALL;

  cout<<"What is the desired accuracy for root-finding? ";
  cin>> ROOT_ACC;


  XL = XB;

  while ( true ) {
    YL = F ( XL );
    XR = XL + STEPSIZE;
    YR = F ( XR );

    if ( YL * YR > 0 ) {
      if ( XR >= XND ) goto end;

      XL = XR;
      YL = YR;
    }

    if ( YL * YR == 0 ) {
      if ( YL == 0.0 ) {
        cout<<"This is a root. "<< XL<<endl;

        if ( XR >= XND ) goto end;

        XL = XR;
      }
      else {
        cout<<"This is a root. "<< XR<<endl;

        if ( XR >= XND ) goto end;

        XL = XR + STEPSIZE;
      }
    }//end if

    if ( YL * YR < 0 ) {
      XS = XR;

      while ( true ) {
        X = ( XL + XR ) / 2;
        Y = F ( X );

        if ( YL * Y > 0 ) {
          XL = X;
          YL = Y;
        }

        if ( YL * Y == 0 ) {
          cout<<"This is a root. "<< X<<endl;

          XR = X;
          YR = Y;
        }

        if ( YL * Y < 0 ) {
          XR = X;
          YR = Y;
        }

        if ( fabs(XR - XL) < INT_ACC) {
         cout<<"This interval contains a root at "<< XL <<','<< XR<<endl;
	
		  XO = (XL + XR)/2.0;

		  TALLY = 1;

		while ( true ) {
		  FX = F(XO);
		  DFX = DF(XO);
		  DDFX= DDF(XO);

		  if (fabs(DDFX)>= TOO_BIG) {

	                cout<<"Condition 1 FAILS: 2nd derivative too large. ";

		  }
		  break;
		}//end of while

		if (fabs(DFX) <= TOO_SMALL) {

		cout<<"Condition 2 FAILS: 1st derivative too close to zero. ";

			}
		}//end if

		if (TALLY > 15) {
		cout<<"Slow convergence. Possible infinite loop.";

		}
	  }//end while

			XN = XO - (FX/DFX);

			if (fabs(XN-XO) < ROOT_ACC) {
				cout<<"The root is: "<<XN<<endl;
			}

			else

				XO = XN;
			TALLY = TALLY + 1;
			break;

		}
  


			XL = XS;

          if ( XL >= XND ) goto end;

          break;

		  cout<<"Would you like to run the program again? (Y or N)";
		  cin>>ANSWER;
     

end:
  return 0;
}

line 58 assigns u a NULL while loop... where are the brackets dude... you will never be able to get out of this...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.