multiple() is defined as returning
void, so you can't use it in an expression.
I think what you would like to do is
1 2 3 4 5
|
bool multiple( int n, int divisor )
{
// return true or false depending on whether 'n' is a multiple of 'divisor'
// (that is, whether or not 'divisor' evenly divides 'n')
}
|
Remember, you
must declare a variable before you use it. Since
num1 and
num2 are the same as
a and
b, why create extra variables?
If you want to make the routine recursive, you must provide a way out. Currently it does not. An excellent example is the GCD algorithm.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// Euclid's method
int euclid_gcd( int a, int b )
{
if (b == 0)
return a;
else
return euclid_gcd( b, a % b );
}
// Dijkstra's method
int dijkstra_gcd( int a, int b )
{
if (a == b)
return a;
else if (a > b)
return dijkstra_gcd( a-b, b );
else
return dijkstra_gcd( a, b-a );
}
|
In both cases, there are at least two branches of execution: at least one without a recursive call and others with a recursive call. For Euclid, we quit when the divisor becomes zero (there are no more divisors). Dijkstra does basically the same thing, except instead of using modulus he uses straight subtraction. When the two sides equal then they must be the common divisor.
The global scope complaint is because you are trying to use the variable
x that exists in the function
main(), but from the function
multiple(). You can't do that, so the compiler doesn't even look for
x in
main() and complains that it does not exist as a global variable.
Hope this helps.
[edit] Woah, I'm a slowpoke...