Question #318538

Example:

Base integer = 3

Initial factor = 2

Number of times to process = 3

Process:

1.) 2 x 3 = 6

2.) 6 x 3 = 18

3.) 18 x 3 = 54


Therefore, the output would above would be 54.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for the 3 integer inputs required for this program and calls the getResult().
  2. This getResult() function has the following details:
  3. Return type - int
  4. Name - getResult
  5. Parameters
  6. int - Base integer
  7. int - Initial factor
  8. int - Number of times to process
  9. Description - this is a recursive function which implements the desired behavior explained in the problem description
  10. The getResult() function is partially implemented already. Your only task is to add the correct recursive case.

Expert's answer

#include <iostream>

using namespace std;

int getResult(int base, int initial, int times)
{
	while (times > 0)
	{
		cout << initial << " x " << base << " = " << initial*base << endl;
		if(times==1)
			return getResult(base, initial, times - 1);
		else
			return getResult(base,base*initial,times-1);
	}
	return initial*base;
}

int main()
{
	int base, initial, times;
	cout << "Please, enter a base integer: ";
	cin >> base;
	cout << "Please, enter an initial factor: ";
	cin >> initial;
	cout << "Please, enter a number of times to proccess: ";
	cin >> times;
	cout<<"Result is "<<getResult(base, initial, times);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS