NEED HELP FAST--Loops

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GolfinRover
    New Member
    • Oct 2008
    • 5

    NEED HELP FAST--Loops

    Using the Newton-Raphson method, find the two roots of the equation 3x^2 + 2x -2=0. (Hint: There is one positive root and one negative root.)

    (x+1) = x - (3x^2 +2x -2) / (6x +2) This is the equation given for the Newton-Raphson method.
    Expand|Select|W rap|Line Numbers

    Head File
    #include <iostream>
    #include <cmath>
    using namespace std;
    #include "Newton.cpp "
    #include "Euler.cpp"
    #include "displaymenu.cp p"

    Main Program File

    #include "head.h"

    int main(void) //Note…some code will be removed after buffering test.
    {
    //Declare all variables here that are needed to call/receive values for Exercises
    double guess=1.0, root=0.0; //variables needed for Exercise 6.a. in case A.
    double differs=0.00000 1, eApprox=0.0; //variables needed for case B.
    char choice = 81; // 81 is decimal code for capital Q; 113 is lower case q
    int enterkey;
    do {
    //Your displaymenu() function will replace the next 6 steps
    cout <<"Call displaymenu and enter an a ";//desplaymenu()
    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<<"Call Newton(given guess), returns and saves root\n "; // Exercise 6.a.
    root=Newton(gue ss);
    cout<<"Newton's root is: "<<root;
    break;
    case 'B':
    cout<<"Call Euler(given differs), returns and saves eApprox\n"; // Exerrcise 3.
    cout<<" differs is set to: "<<differs<<end l;
    //eApprox = Euler(differs);
    cout<<" eApproximate is: "<<eApprox<<end l;
    break;
    default: //input data validation intercepted here
    if (choice != 'Q') // a decision structure to skip or enter next {block}
    {cout << "\nIncorrec t Choice: Enter (A,B, or Q as valid)\n";
    }//endif
    } // end switch

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

    cout << " Fini\n";


    system("pause") ;
    return 0;
    } // end main


    Newton File My newton does not work at the moment.
    double Newton(double x) // returns y = f(x)
    {
    double root;
    int count;
    for (count = 1; count < 10; count++);
    {

    cout<<" The x value of Newton is: "<<x<<endl;
    cout<<"The root: "<<root<<en dl;
    root=x-((3(pow((x),2)) +2x-2)/(6x+2));
    }//end for
    return root;

    } //end Newton

    I still didnt make the Euler file or displaymenu file.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    Please dont double post .

    raghu

    Comment

    Working...