The following c code should compare float eur to an array a[k]. If I set eur = 0.05, 0.5, 5, 50, 500 the compiler finds the match. for any other value (e.g. 2, 10, 0.02) it does not find the match. The output picture is attached to this post.
1.) How come that the value in the marked line is not matched?
2.) Where do those odd values come from? actually they are expected to behave like shown in "a[3] = 10"
int pruef(float eur)
{
int i, j=0, k, l=15;
float n, z, a[l];
for(i=0; i < 3; i++)
{
switch (i){
case 0: z=0.01; break;
case 1: z=0.02; break;
case 2: z=0.05; break;
}
for(n=z; n < 501; n*=10){
a[j] = n;
j++;
}
}
for (k=0; k<l;k++)
{
printf("\na[%d]: %4.2f", k, a[k]);
}
for(k=0; k<l; k++)
{
printf ("\n 'eur' %f == %f array[k]", eur, a[k]);
if (eur == a[k]) return 1;
else continue;
}
return 0;
}
Here is the output:
2
a[0]: 0.01
a[1]: 0.10
a[2]: 1.00
a[3]: 10.00
a[4]: 100.00
a[5]: 0.02
a[6]: 0.20
a[7]: 2.00
a[8]: 20.00
a[9]: 200.00
a[10]: 0.05
a[11]: 0.50
a[12]: 5.00
a[13]: 50.00
a[14]: 500.00
'eur' 2.000000 == 0.010000 array[k]
'eur' 2.000000 == 0.100000 array[k]
'eur' 2.000000 == 1.000000 array[k]
'eur' 2.000000 == 9.999999 array[k]
'eur' 2.000000 == 99.999992 array[k]
'eur' 2.000000 == 0.020000 array[k]
**'eur' 2.000000 == 0.200000 array[k]**
'eur' 2.000000 == 2.000000 array[k]
'eur' 2.000000 == 19.999998 array[k]
'eur' 2.000000 == 199.999985 array[k]
'eur' 2.000000 == 0.050000 array[k]
'eur' 2.000000 == 0.500000 array[k]
'eur' 2.000000 == 5.000000 array[k]
'eur' 2.000000 == 50.000000 array[k]
'eur' 2.000000 == 500.000000 array[k]
zahl nicht vorhanden
------------------
(program exited with code: 0)
Press return to continue