Answer to Question #330703 in C++ for Secret Agent

Question #330703

Poorly Executed Mitosis

by CodeChum Admin

A mitosis program has gone out of hand and now does abnormal cell duplication. Rather than scrapping the project, the researchers decided to observe and predict the cell duplication using a program.


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.

Input


1. Base integer

2. Initial factor

3. Number of times to process

Output


Enter·base·integer:·3
Enter·initial·factor:·2
Enter·number·of·times·to·process:·3
Result·=·54




1
Expert's answer
2022-04-19T08:07:06-0400
#include <iostream>

using namespace std;

int GetResult(int base, int factor, int times)
{
	while (times > 0)
	{
		base *= factor;
		times -= 1;
		return GetResult(base, factor, times);
	}
	return base;
}

int main()
{
	int base, factor, times;
	cout << "Please, enter base integer: ";
	cin >> base;
	cout << "Please, enter factor integer: ";
	cin >>factor;
	cout << "Please, enter times integer: ";
	cin >> times;
	cout << "Result = " << GetResult(base, factor, 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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS