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

Question #330700

Slowly But Surely

by CodeChum Admin

In life, good things take time.


Let's make a simple program that mirrors this beautiful idea where we ask the user for two integer inputs. The first one would represent the starting number and the second one would represent the next n integers after it.


For example, if the first number inputted is 2 and the second number inputted is 3, then the output would be 3, 4, 5 because these are the next 3 integers after 2.


Instructions:

  1. In the code editor, you are provided with a main() function that asks the user for two integers and calls the slowDisplay() function.
  2. This slowDisplay() function is a recursive function which should perform the functionality explained in the problem description above.
  3. This function is only partially implemented as it lacks a base case. Your task is to add the base case needed by this recursive function.

Input


1. Starting integer

2. Number of integers

Output


Enter·starting·integer:·2
Enter·how·many·next·integers:·3
3·4·5
1
Expert's answer
2022-04-19T03:08:24-0400
#include <iostream>

using namespace std;

void slowDisplay(int start,int n)
{
	while (n>0)
	{
		start++;
		n--;
		cout << start << " ";
		return slowDisplay(start, n);
	}
}

int main()
{
	int start, next;
	cout << "Please, enter starting integer: ";
	cin >> start;
	cout << "Please, enter how many next integers: ";
	cin >> next;
	slowDisplay(start, next);
}

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