This function is supposed to take a base number and exponent and calculate the total. The syntax is all fine, but the problem is that no output comes out when I run the program. Here is the program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <cmath>
usingnamespace std;
int power2(unsignedint y,unsignedint z){
if (z == 0) return 1;
if (z == 1) return y;
else {
return y * power2(y, z - 1);
}
}
int main(){
int a, b;
cin >> a;
cin >> b;
power2(a, b);
return 0;
}
I tried putting in cout << ... and then it printed the value of y along with some really strange numbers. For example, if I put 2 as the base number and 3 as the exponent this is the output: