Im trying to Write a function that accepts two input parameters and computes the result of raising the value of the first input to the value of the second input, and returns the result. You are not allowed to use the multiplication operator(*)for performing multiplication, nor are you allowed to use any built-in C++ functionality that directly produces the exponentiation result.
Data Types: function works correctly for both inputs being positives, zeroes, or ones, and when the second input is negative. my return is always 0 what am I doing wrong
#include <iostream>
using namespace std;
int exp(int, int);
int main()
{
int num1, // to store first number
num2, // to store second number
value = 0;
// read numbers
cout << "Enter first number: ";
cin >> num1;
cout << "Enter second number: ";
cin >> num2;
// call function
exp(num1, num2);
// print value
cout << "The value of " << num1 << " to the " << num2 << " is: " << value << endl << endl;
system("pause");
return 0;
}
// function definition
int exp(int a, int b)
{
int result = 0;
for (int i = 0; i < a; i++)
{
result += b;
}
return result;
}