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

• 03-25-2002
Halo
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);
}
• 03-25-2002
Nit
My eyes are bloodshot also from reading that code with no '[code]' tags.
• 03-25-2002
Halo
lol, what are code tags we have not learned about those yet :-)
• 03-25-2002
quzah
 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.
• 03-25-2002
Halo
lol, Well now that I learned about Code Tags anyone have any idea where the error is in my code ?
• 03-26-2002
foniks munkee
But where are they? (The code tags that is)
• 03-26-2002
Govtcheez
you could type them in manually, or press the button with the # symbol next to the php button.
• 03-26-2002
foniks munkee
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.. :)
• 03-26-2002
Deckard
For Halo's benefit
Quote:

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; }```