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&);
result checkNumbers (int& a, int& b, int& c)
{
result resReturn;
if (c*c > a*a + b*b)
{
++a;
++b;
c -= 2;
resReturn = greater;
}
elseif (c*c < a*a + b*b)
{
--a;
--b;
c += 2;
resReturn = less;
}
elseif (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.