DECLARATION SYTAX ERROR

Can someone help me out with this? I keep getting a "Declaration syntax error" at line ""int main()". Is there something wrong with my int main()? And how do i go about it? Thanks in advance! Here is the program:


#include<stdlib.h>
#include<iostream.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>

float rung4(float x, float y, float h)
int main()
{

float eps=0.00001;
double y0,x0,y1,n,f,k1,k2,k3,k4 ;

do
{
printf("\nEnter the value of x0: ");
scanf("%lf",&x0);
printf("\nEnter the value of y0: ");
scanf("%lf",&y0);
printf("\nEnter the value of h: ");
scanf("%lf",&h);
printf("\nEnter the value of last point: ");
scanf("%lf",&n);
for(x0=0; x0<n; x0=x0+h)
{
f=F(x0,y0);
k1 = h * f;
f = F(x0+h/2,y0+k1/2);
k2 = h * f;
f = F(x0+h/2,y0+k2/2);
k3 = h * f;
f = F(x0+h/2,y0+k2/2);
k4 = h * f;
y1 = y0 + ( k1 + 2*k2 + 2*k3 + k4)/6;
}
float max(float *y0, float *y1, float n)
{
float max=fabs(y0[0]-y1[0]);
for (i=1; i<n; i++)
if (fabs(y0[0]-y1[2*i>max])
max =fabs(y0[0]-y1[2*i>max);
return max;
}


printf("\n\n y(%.4lf) = %.3lf ",x0+h,y1);
y0=y1;

}
while((max(y0,y1, n/2)/15)>=eps);
puts("Runge-kutta 4th order");
for(i=0; i<n/2+1; i++)
printf("x[%d]=%.2f y[%d]=%.5f\n", i, x[i], i, y[i]);
getch();
return 0;
}

Last edited on
The first thing I see is that you need a semicolon where you are declaring run4().

Also, use the code tags (they are under Format and look like <>) the next time you post your code.
@kooth Putting a semicolon aftrer rung4() yields even larger numbers or errors.
That means that there are more errors in your code. The semicolon is necessary. When that error remains, the compiler doesn't bother trying to compile main(), so it doesn't see the errors.

Fix the semicolon problem and let us know what errors you see now.
@doug, here are the major errors:
Says function F should have a prototype at line <f=F(x0,y0);>
Delclaration syntax error at line <{> (after <float max(float *y0, float *y1, float n)>)
Max function should have a prototype at line <while((max(y0,y1, n/2)/15)>=eps);>
closed account (zb0S216C)
A function definition cannot appear within a definition of another function. Move the definition of max() to the global namespace.

Wazzak
Last edited on
The reason it says that F should have a prototype is because there is no prototype for function F. You need to state somewhere above your definition of main:

double F(double x, double y);

And then you need to define that function.

Also, as kooth said, wrap your code in code tags (the <> in the Format options--they are very easy to use). Not only will they make your code easier to read, but they will give line numbers you can reference. Just click the "Preview" button and you can see your whole post, code and all.

Topic archived. No new replies allowed.