#include<stdio.h>
#include<conio.h>





 int main()
{
float fill_h[400],fill_s[400],bh_p[400],ex_up,ex_upt;
int i,j,p;float lam = 0.5;
float fhf = 1.8288 , fhi = 0.6096 , fsi = 12.0f , fsf = 19.0f ;
fill_s[0] = fsf;fill_h[0] = fhi;bh_p[0] = bhpeqns(fhi,fsf);
for(i=1 ; lam > 0.002 ;i++)
{
printf("\n the loop is run");
if(fill_h[i-1] == 1.8288)
    {
        fill_h[i-1] = fhi;
        fill_s[i-1] = (fill_s[i-1] - 1);
        lam = 0.5;
    }

    while((fill_s[i-1] > 11.0f))
    {

    fill_h[i] = fill_h[i-1] + lam ;
    fill_s[i] = fill_s[i-1];

    printf("\n %d   fh  --   %f     fs  --    %f",i,fill_h[i],fill_s[i]);
    printf("\n %f",lam);
    ex_up = fill_h[i] + lam;

    if(ex_up > fhf)
    {
        lam = lam/2;

        ex_upt = fill_h[i] + lam;

        if(ex_upt > fhf)
        {
            lam = ((fhf - fill_h[i])/2);
        }
    }


     else
    {
        lam = lam;
    }   
    p   = i ;
    printf("\n %f",lam);
    i++ ;
    }
}
printf("\n  i   -   fh  -   fs  -   ");
for(i = 0 ; lam > 0.002 ; i++)
{
printf(" \n %d   %f   %f",i,fill_h[i],fill_s[i]);
}

return 0;
}

What is not working? We are mere humans, not gods!
Btw. its (in your title) should be written as it's.

for(i=1 ; lam > 0.002 ;i++)

That looks like a very very dangerous and unpredictable loop. What happens if the value of lam is never > 002? Or if the value of lam becomes > .002 only after the value of i is greater than 400? You need to rethink what that loop is doing.

A suggestion, in your first loop, use i < 400 as the upper limit for the loop. Then at the bottom of the loop test for lam > .002 and make i equal 400 once lam is less than or equal to .002. This way you have a way to exit the loop when you want, and still keep it within the bounds of the array. Something like:

if(lam <= .002)
{
    i = 400;
}

In your second loop just use i < 400 as the upper limit.

Edited 3 Years Ago by tinstaafl

Also it's very dangerous to compare doubles using the equals operator:

if(fill_h[i-1] == 1.8288)

If there is a small precision change, unpredictable results will occur. To compare doubles, check the absolute difference between what you are trying to compare and see if falls below a tolerance of your choice, such as

if (fabs(fill_h[i-1] - 1.8288) < 0.0001)

The precision of the comparision is thusly determined by the tolerance you provide.

Comments
Indeed, and often forgotten.
This article has been dead for over six months. Start a new discussion instead.