1. ## loop problem

Hello,

I have to find the greatest number a user enters.
When the user enters a ) or a number smaller then 0 then the output has to stop,
Code:
```
#include        <stdio.h>

int
main ( int argc, char *argv[] )
{
float getal, grootste  ;
getal = grootste = 1 ;
do
{
printf("Enter a number : ");
scanf ("%f", &getal);
printf ("Ingevoerde getal : %f", getal) ;
}
while (getal <=0);
printf ("Het grootste getal is %f", grootste);
return 0 ;
}                               /* ----------  end of function main  ---------- */```
But when the user enters one number the loop stops.
What is my thinking error here ?

Roelof

2. You are confusing less than with greater than.

Quzah.

3. Hello,

Thank you.
The while must be while (getal > 0)

Still one question:

When I enter the numbers : 60, 38.3, 4.89, 100.62, 75.2295 I get as output 100.620003 instead of 100.62.

Is there a reason for that ?

Roelof

4. Floating point - Wikipedia, the free encyclopedia
Yes, all floating point numbers are approximations.
If your float does not have an exact representation, you end up with the nearest approximate value instead.

5. oke,

I read the page you told me.
So I cannot do anything about it.

Can I then make the conclusion that floats are not good for calculations.
When a number has no exact represantation then it will be approximate.
So that round up can make the outcome otherwise then expected.

Roelof

6. Originally Posted by roelof
oke,

I read the page you told me.
So I cannot do anything about it.

Can I then make the conclusion that floats are not good for calculations.
Roelof
No, that is not a good conclusion to draw.

7. O,

Why not.
If 100.62 will be 100.620003 and I will multiple the number by itself then the answer would be 10124.38500372 instead of 10124.3844
Or if I want to compare they will not be the same.

Roelof

8. Here is a short read -> Floating Point
And a long read -> What Every Computer Scientist Should Know About Floating-Point Arithmetic
If you really care about rounding errors and so forth, then good use of floating point is quite hard work. You have to manage those accumulated errors in some way.

Simple answer - multiply everything by 100, so you're doing 10062 * 10062.
Accurate, but you might run out of integer head room (overflow), and you have to keep track of where the decimal point should be.

Less simple answer -> Fixed-point arithmetic - Wikipedia, the free encyclopedia
Easier in C++, since you can overload all the operators in a useful way, and make it seem like nothing unusual is happening in the code.

Meh, this is too hard, I'll get a maths library, say The GNU MP Bignum Library

9. O,

Why not.
If 100.62 will be 100.620003 and I will multiple the number by itself then the answer would be 10124.38500372 instead of 10124.3844
Or if I want to compare they will not be the same.

Roelof
It's not a good conclusion to make simply because it is too broad. You can certainly compare decimal approximations, and make two of them the same. You just need to know that in order to be the same, you're going to consider certain digits important and ignore the rest. Most floating point operations will not be too bad unless you really shouldn't have used floating point to begin with because you needed integers instead.

10. Hello,

Oke,

I will study it.
Everyone thanks for the help and patience.

Roelof