I'm having trouble with two recursive programs, which don't work properly. Can someone look at these (DO NOT post complete solutions, only suggestions) :
Code:
#include <iostream>
using namespace std;
int pow( int base, int exp ) {
if (exp == 0) {
return 1;
}
else {
return base * pow(base,exp-1);
}
}
int main ( ) {
int base;
int power;
cout << "This program calculates exponential values." << endl;
cout << "Enter the base: ";
cin >> base;
cout << "Enter the power: ";
cin >> power;
cout << "" << endl;
cout << base << "^" << power << " = " <<
cout << pow(base, power);
}
and
Code:
#include <iostream>
using namespace std;
int gcd(int number1, int number2) {
if(number1 || number2 >= 0) {
return gcd(number2, number1 % number2);
}
else if(number1 || number2 == 0) {
return 1;
}
}
int main ( ) {
int number;
int another;
int gcdd;
cout << "This program calculates the greatest common divisor (GCD) for two integers." << endl;
cout << "Enter a number: ";
cin >> number;
cout << "Enter another: ";
cin >> another;
cout << "" << endl;
cout << "GCD = " << gcd(number, another);
}