Help with a function in a numer-to-english program

Hello people. Im trying to make a "number to english" translator, and one of the functions of the program is that shown below (which is not working). Can someone tell me what is wrong with it, pleeeease?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  string countTo10decim (double a)
{
if ((a==0,21) || (a == 0,31) || (a == 0,41) || (a == 0,51) || (a == 0,61) || (a == 0,71) || (a == 0,81) || (a == 0,91))
{
    return "one";
}
else if ((a == 0,22) || (a == 0,32) || (a == 0,42) || (a == 0,52) || (a == 0,62) || (a == 0,72) || (a == 0,82) || (a == 0,92))
{
    return "two";
}
else if ((a == 0,23) || (a == 0,33) || (a == 0,43) || (a == 0,53) || (a == 0,63) || (a == 0,73) || (a == 0,83) || (a == 0,93))
{
    return "three";
}
else if ((a == 0,24) || (a == 0,34) || (a == 0,44) || (a == 0,54) || (a == 0,64) || (a == 0,74) || (a == 0,84) || (a == 0,94))
{
    return "four";
}
else if ((a == 0,25) || (a == 0,35) || (a == 0,45) || (a == 0,55) || (a == 0,65) || (a == 0,75) || (a == 0,85) || (a == 0,95))
{
    return "five";
}
else if ((a == 0,26) || (a == 0,36) || (a == 0,46) || (a == 0,56) || (a == 0,66) || (a == 0,76) || (a == 0,86) || (a == 0,96))
{
    return "six";
}
else if ((a == 0,27) || (a == 0,37) || (a == 0,47) || (a == 0,57) || (a == 0,67) || (a == 0,77) || (a == 0,87) || (a == 0,97))
{
    return "seven";
}
else if ((a == 0,28) || (a == 0,38) || (a == 0,48) || (a == 0,58) || (a == 0,68) || (a == 0,78) || (a == 0,88) || (a == 0,98))
{
    return "eight";
}
else if ((a == 0,29) || (a == 0,39) || (a == 0,49) || (a == 0,59) || (a == 0,69) || (a == 0,79) || (a == 0,89) || (a == 0,99))
{
    return "nine";
}
}
by the way, the problem is:in the "main" program, there is this "else" condition:

else if (a > 20 && a < 100)
{
cout << count20To100(a) << " ";
a = a/100;
cout<< countTo10decim(a) << endl;
}

when it calls the function showed above, for any number over 20, it always show, i.e., "twenty one", "thirty one", and doesnt change if i ask him to show, i.e., 22 (the first line of the function´s if statement is never overcome). Im blowing my mind with this!
if ((a==0,21) || /* ... */

The comma doesn't do what you think it does.
What it actually does is evaluates a == 0 and then evaluates and returns the value of 21.

So you essentially get
3
4
5
6
if (21 || 31 || 41 || 51 || 61 || 71 || 81 || 91)
{
    return "one";
}
so of course that if statement will always be executed.

If you wanted a decimal point, use 0.21 instead of 0,21.
But be warned that it probably still won't work, because floating point values are inexact and so the value of a won't necessarily compare equal to any of those values (you might end up with, say, a 0.0000000001 difference, which will cause the comparison to still come out false).
Topic archived. No new replies allowed.