I am writing a simple program to calculate 6^5 using a function. Here's my code
#include <iostream>
using namespace std;
int raiseToPower(int &base, int exponent){
for (int i = 1; i < exponent; i = i + 1){
base= base * base;
}
return base;
}
int main() {
int base = 6;
cout << "6^5 is " << raiseToPower(base, 5)<< endl;
return 0;
}
The result is
6^5 is -683606016
instead of 7776
Can you guys explain to me why I got this result? I am not looking for another way to write this code. I know there are simpler ways but I am trying to understand what went wrong