#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;
}
sai.aleenus
0
Newbie Poster
Recommended Answers
Jump to Postfor(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 …
Jump to PostAlso 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 …
All 5 Replies
ddanbe
2,724
Professional Procrastinator
Featured Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
tinstaafl
1,176
Posting Maven
MonsieurPointer
ddanbe
commented:
Indeed, and often forgotten.
+14
sai.aleenus
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.