Problem using enumerations

Hi,

I'm pretty new to C++, but I have been trying to use enumerations to help with a return of a function, which can have three results. Here is my enum declaration and function prototype:

1
2
enum result {greater = 0, less = 1, equal = 2};
result checkNumbers (int&, int&, int&);

Here is the function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
result checkNumbers (int& a, int& b, int& c)
{
     result resReturn;  
     if (c*c > a*a + b*b)
     {
             ++a;
             ++b;
             c -= 2;
             resReturn = greater;
     }
     else if (c*c < a*a + b*b)
     {
             --a;
             --b;
             c += 2;
             resReturn = less;
     }
     else if (c*c == a*a + b*b) resReturn = equal;
     return resReturn;
}

I call this from int main()
Is there anything I have done wrong?
When I compile - w/ Dev-C++ - it gives me this error:

In function `result checkNumbers(int&, int&, int&)':
`greater' undeclared (first use this function) 
(Each undeclared identifier is reported only once for each function it appears in.)
`less' undeclared (first use this function)
`equal' undeclared (first use this function) 
Personally I would make this function look like this:

first reason is to reduce the amount of math the processor has to do with each step. If there is a problem it will be easier to debug at some point if the math went wrong.

In less the enumeration defined in a different file or behind the function header in the file it should be seen.

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
40
41
enum result {greater = 0, less = 1, equal = 2};

result checkNumbers (int& a, int& b, int& c)
{
        result resReturn;

        int csquared = c*c;
        int asquared = a*a;
        int bsquared = b*b;
        int absum = asquared + bsquared;

       if(csquared == absum)
       {
            resReturn = equal;
       }
       else 
       {
             if(csquared > absum)
             {
                   ++a;
                   ++b;
                   c -=2;
                   resReturn = greater;
             }
             else
             {
                   --a;
                   --b;
                   c+=2;
                   resReturn = less;
             }
        }
 
        return resReturn;
}

int main()
{
    ....
}

Topic archived. No new replies allowed.