I am writing two programs. One raises a number to the other number's power, and the other does greatest common divisor. Both of them crash using infinite recursion and I can't figure out why. Can someone look at these and give me suggestions? Please do not post complete solutions, only suggestions.
#include <iostream>
using namespace std;
int pow( int base, int exp ) {
int somevariable = pow(base,exp-1);
if (base == 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);
}
#include <iostream>
using namespace std;
int gcd(int number1, int number2) {
int returnj = 0;
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);
}