0
Gustavo is 1.40 meters and grows G centimeters per year, while Juliano is 1.10 and grows J centimeters per year.
My show is giving a loop infinite when I run.
#include<stdio.h>
int main()
{
float g,j,gus=1.40,jul=1.10;
int cont=0;
scanf("%lf %lf",&g, &j);
while(jul<=gus)
{
jul=jul+j;
printf("%lf\n",jul);
gus=gus+g;
printf("%lf\n",gus);
cont++;
}
printf("%d",cont);
}
Hello Flávio, probably the jul is not reaching the value of Gus;
– Maurício Z.B
And what should I do? It depends on the input, if
j
is less than or equal tog
this is the correct behavior. It should have a test stop point to be something that has some logic. Maybe the exercise was ill-defined, but we don’t know what he looks like.– Maniero
sure would be if I put as input 8 and 17, the cont should come out 4, being that jul surpassed Gus, but stays in the loop, which can be?
– flavio
There seems to be a problem of magnitude of measures there, need to decide whether to work with meters or will convert between them. What is right?
– Maniero
Change to
while(jul<=gus && cont < 20)
and say what appears on the way out.– Victor Stafusa
i managed to tidy up now, instead of by %lf, I put %f and divide g and j by 100 before adding, now ta hitting. vlw guys
– flavio
That? https://ideone.com/GsqXRf
– Maniero
Yeah, now it’s out of the loop and it’s hitting the result, vlws
– flavio