I am (new to c++) trying to create a power function manually and came across the issue where if the power inputted is negative, the result is always being printed out as 0. I suspect that one of the variables might not be declared properly, can you help please
#include <iostream>
using namespace std;
int power;
float result = 1, base;
int firs();
void pow(int base, int power);
int main()
{
firs();
pow(base, power);
return 0;
}
int firs()
{
cout << "Enter a base input: ";
cin >> base;
cout << "Enter a power input: ";
cin >> power;
return base, power;
}
void pow(int base, int power)
{
cout << "With a given base of " << base << " and a given power of " << power << endl;
if (power > 0)
{
for (int i = 0; i < power; i++)
{
result = result*base;
}
cout << "The final answer is: " << result;
}
else if (power < 0)
{
for (int i = 0; i > power; i--)
{
result = result*(1/base);
}
cout << "The final answer is: " << result;
}
else
{
cout << "The final answer is: " << 1;
}
}