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

This is a discussion on N00b Question. Can't get this program to work with me !!! within the C Programming forums, part of the General Programming Boards category; Okay finally got this program done there is only one problem, it goes only to 4.0000 And I need it ...

1. ## 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. My eyes are bloodshot also from reading that code with no '[code]' tags.

3. lol, what are code tags we have not learned about those yet :-)

4.  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.

5. lol, Well now that I learned about Code Tags anyone have any idea where the error is in my code ?

6. But where are they? (The code tags that is)

7. you could type them in manually, or press the button with the # symbol next to the php button.

8. 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..

9. ## 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;
}```

Popular pages Recent additions