I'm trying to create a function that uses loops to determine the roots of an equation using the Newton-Raphson method. I have my Newton function set up to take the input from my main prog, calculate the roots, and then return them back into the main prog. Somewhere along the lines something is going wrong. When I input my negative and positive values, I receive my first line of output "Call Newton<given guess> saves root and returns function" but then the program stops. I'm not sure if this is a problem with my loop, my Newton function, or with my program calling the Newton function. here is my code

Main program

#include "head.h"

int main(void)	

double guess, root;	//variables needed for Newton.
char choice = 81;  // 81 is decimal code for capital Q; 113 is lower case q
int enterkey, i;
do {

cout << "\nmenu displayed:  Enter A for 6.a., B for 3., or Q to quit ";

    	cout << "\nFor example, type B for Exercise 3 followed by Enter key  ";
    	choice = toupper(getchar( ));  enterkey = getchar( );
   	 cout << choice <<":"<< enterkey << endl;
switch (choice)	// a decision structure to select only one case out of many

case 'A':	
	cout<<"Enter a negative followed by a positive "<<endl;
	cout<<"Call Newton(given guess), returns and saves root\n";	
	cout<<"After Newton the root is "<<Newton(guess)<<endl;
	}//end for
	cout<<"After the loop i is  "<<i<<endl;
if (choice != 'Q')	
{cout << "\nIncorrect Choice: Enter (A,B, or Q as valid)\n";
} //  end switch

} while (choice != 'Q');  //end do-while

cout << " Fini\n";

return 0;

and here is my Newton function

double guess, xi,root;
int i;
double Newton(double guess)
	for (i=1,10;1;)
	}//end for
	root =xi;	
	cout<<"in Newton\n";
		return root;
10 Years
Discussion Span
Last Post by crahhhhhb

basically what i'm trying to do is make the newton function accept two numbers, plug them through the equation f(x)/f'(x) and return a root. I then want prog.cpp to return that root

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.