1. ## "for" loop problems....

When I try to compile the following code in borland it tells me that there is incorrect syntax with the for () loop and that the statement is missing. I don't understand why the syntax is wrong, i have put an initializing statement, then a condition, then the increment increaser... Can anyone suggest what I may have done wrong... Any help greatly appreciated.

note: the program is designed to calculate the time of filling of a tank with varying radi with height by means of trapezoidal integration.

Code:
```

#include<stdio.h>
#include<math.h>
main()
{
/*declaring variables*/
float i,h,r,p;
float hlevel,llevel;
float D1, D2, D3;
float Qo,Qi,dt,w;
float time;

/*declaring functions*/
/*float time( float r);*/

/*defining variables*/
#define n 500;
#define pi 3.1415926535897932384626433832795;
#define g 9.81;

D1= 6.0;
D2= 3.7;
D3= 2.7;
hlevel= 0.5;
llevel= 5.0;
w=(hlevel-llevel)/n;

/*getting user input for density*/
printf("Welcome to the surge tank simulator program\n");
printf("Please enter the liquid density (kg/m^3):\n");
printf("p=");
scanf("%f", &p);

/*trapezoidal integration using for loop*/

for(i=1;i<n;i++)
{
h= 0.5+(i*w);
Qo= 0.000004*(sqrt((p*g*h)));
Qi= 300;

if(h <= D3 && h >= 0.5)
{
r= 1.5;
}

if(h <= D2 && > D3)
{
r= (0.5)*(5.7-h);
}

if(h <= 5.0 && > D2)
{
r= (3.5/3.22)*(h - 2.78);
}

dt=  ((pi*(r*r))/(Qi-Qo))*w ;
time= time + dt;

} /*end for... i.e. i does not equal less than or equal to n*/

printf( "The high level alarm sounds after %f, hours\n", time);
} /*end main*/```

2. you don't need semicolans after #defines

Code:
```#define n 500
#define pi 3.1415926535897932384626433832795
#define g 9.81```
And I am not sure if its a good idea to have #defines inside your main() (or any other function for that matter). It should be declared outside functions and above main() in this case or in some other header (.h) file which you will have to include using #include directives.

The function declaration should also be (not necessary though) moved above main() globally.

3. >>It should be declared outside functions and above main()

Most people do but there is no reason why you should or shouldn't.

4. Sorry i meant to delete that function hence why it has comment tags... I just removed the ;'s from the defines...

I think I have it worked out now though... I just noticed that the if ()'s were not written properly...

5. ## for loop proble

I think there is nothing wrong with for loop. You should use define after header files. There are error in if condition.
Code:
`if(h <= D2 && > D3)`
use
Code:
`if(h <= D2 && h> D3)`
and
Code:
` if(h <= 5.0 && > D2)`
any way here the complete programme without any error.
Code:
```#include<stdio.h>
#include<math.h>
/*defining variables*/
#define n 500
#define pi 3.1415926535897932384626433832795
#define g 9.81

int main(void)
{
/*declaring variables*/
int i,h,r,p;
float hlevel,llevel;
float D1, D2, D3;
float Qo,Qi,dt,w;
float time;

/*declaring functions*/
/*float time( float r);*/

D1= 6.0;
D2= 3.7;
D3= 2.7;
hlevel= 0.5;
llevel= 5.0;
w=(hlevel-llevel)/n;

/*getting user input for density*/
printf("Welcome to the surge tank simulator program\n");
printf("Please enter the liquid density (kg/m^3):");
scanf("%f", &p);

/*trapezoidal integration using for loop*/

for(i=1;i<n;i++)
{
h= 0.5+(i*w);
Qo= 0.000004*(sqrt((p*g*h)));
Qi= 300;

if(h <= D3 && h >= 0.5)
{
r= 1.5;
}

if(h <= D2 && h> D3)
{
r= (0.5)*(5.7-h);
}

if(h <= 5.0 && h> D2)
{
r= (3.5/3.22)*(h - 2.78);
}

dt=  ((pi*(r*r))/(Qi-Qo))*w ;
time= time + dt;

} /*end for... i.e. i does not equal less than or equal to n*/

printf( "The high level alarm sounds after %f, hours\n", time);
return 0;
} /*end main*/```