# Help with my euclidean algorithm program?

• 03-20-2011
miwashi
Help with my euclidean algorithm program?
The error I get is Line 8: error: 'euclidean_algorithm' was not declared in this scope

Does anyone know what's wrong?

Code:

```int main(int argc, char *argv[]) {         int x,y,aa;         cout << "enter number 1: " << endl;         cin >> x;         cout << "enter number 2: " << endl;         cin >> y;         aa=euclidean_algorithm(x,y); } int euclidean_algorithm(int a, int b) {         // the first thing to do is to make sure a > b. If it is not, swap them.         if (b > a) { int t = a; a = b; b = t; }         // now we run the algorithm in a loop         while (b != 0) {             int temp = a % b;             a = b;             b = temp;         }         cout << "the greatest common denominator is " << a << endl; }```
• 03-20-2011
rags_to_riches
The C++ compiler reads files from the top down. When you put euclidean_algorithm as a function call in your main, the compiler goes looking through what it's already found to make sure there's a function with that name. But alas, there is not in this case. You need to prototype the function before you call it in your code.
• 03-20-2011
miwashi
Thanks, I did a line to do that, and now the error is at the end bracket on the last line -

line 28: warning: control reaches end of non-void function

what does this mean?
• 03-20-2011
grumpy
euclidean_algorithm is declared as returning int (returning anything other than void means the function is "non-void", according to your compiler).

There is no return statement before the closing brace at the end of that function. One is needed of the form "return some_integral_value;"