Thread: N00b Question. Can't get this program to work with me !!!

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    52

    Angry N00b Question. Can't get this program to work with me !!!

    Okay finally got this program done there is only one problem, it goes only to 4.0000 And I need it to go all the way down to zero or very close to it. My eyes are bloodshot and I need some help with this thing :-) Thanks in advance

    #include <stdio.h>
    #include <conio.h>
    #include <math.h>
    #define STOP 0.001

    double func1 (double x);
    double func2 (double x);

    double Xro, Xrn, EPS, fXro, fprimeXro;
    int Iter,q;

    void main(void)
    {
    FILE *outptr;

    outptr=fopen("output.txt","wt");


    label3: printf("\nPlease enter a value for Xro");
    scanf("%lf",&Xro);
    printf("\nYou entered Xro= %lf", Xro);
    fprintf(outptr, "\nThe intial guess is Xro= %lf ", Xro);
    Iter=1;
    fprintf(outptr,"\nIter Xro Xrn error");
    label1: fXro = func1(Xro);
    fprimeXro = func2(Xro);
    if (fprimeXro == 0.0) {
    printf ("\n The slope of a function at iteratuin number =%4d\
    \nis equal to zero. Newton-Raphson Method fails. Program is\
    \ngoing to prompt you to start a new initial guess!",Iter);
    goto label3;
    }
    Xrn = Xro -fXro/fprimeXro;
    printf("\nThe new estimate of the root is = %lf", Xrn);
    EPS = fabs((( Xrn - Xro)/Xro)*100.);
    fprintf (outptr,"\n%4d %12.9f %12.9f %12.9f\
    ",Iter,Xro,Xrn,EPS);
    Iter = Iter + 1;
    printf("Do you wish to exit, if so press 0");
    scanf("%li", &q);
    if (q==0) {
    return;
    }
    if ( EPS <= STOP ) {
    printf ("\nRoot = %lf",Xrn);
    fprintf (outptr,"\nRoot is = %lf", Xrn);
    goto label2;
    }
    else {
    Xro = Xrn;
    goto label1;
    }
    label2:
    fclose(outptr);
    getch();
    }
    double func1(double x)
    {
    return( pow(x,2.0) - x -12. );
    }
    double func2(double x)
    {
    return( 2.0*x - 1.0);
    }

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    42
    My eyes are bloodshot also from reading that code with no '[code]' tags.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    lol, what are code tags we have not learned about those yet :-)

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    [edit] Blah. That illustration was fubar. Just forget it. [/edit]

    Edit your original post, and wrap it in [ code ] [ /code ] tags (without the spaces in the [ ]).


    Quzah.
    Last edited by quzah; 03-25-2002 at 11:10 PM.
    Hope is the first step on the road to disappointment.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    52
    lol, Well now that I learned about Code Tags anyone have any idea where the error is in my code ?

  6. #6
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    But where are they? (The code tags that is)

  7. #7
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    you could type them in manually, or press the button with the # symbol next to the php button.

  8. #8
    Registered User foniks munkee's Avatar
    Join Date
    Nov 2001
    Posts
    343
    I should clarify that I wasn't actually asking where the tags are, (as I always use them since my second post) but rather why having learnt what they are he hasn't put them in the code..
    Last edited by foniks munkee; 03-26-2002 at 06:35 PM.

  9. #9
    The Artful Lurker Deckard's Avatar
    Join Date
    Jan 2002
    Posts
    633

    For Halo's benefit

    Originally posted by foniks munkee
    But where are they? (The code tags that is)
    Code tags are used on these forums to preserve spacing, which allows your code to be a bit more readable. The tags are [ code ] and [ /code ] (without spaces between the brackets).

    Code:
    #include <stdio.h>
    
    int main( void )
    {
      printf( "Hello, Halo\n" );
    
      return 0;
    }
    Jason Deckard

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  2. one function in my program won't work....
    By talz13 in forum C++ Programming
    Replies: 12
    Last Post: 04-06-2003, 12:19 PM
  3. program from book wont work
    By cemock in forum C Programming
    Replies: 2
    Last Post: 03-06-2003, 09:58 AM
  4. how do i get this program to work, anyone, anyone?
    By correlcj in forum C Programming
    Replies: 5
    Last Post: 07-04-2002, 10:28 PM
  5. Question about "Answer Key" Program
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 11-14-2001, 09:55 PM