logo CodeStepByStep logo


Language/Type: C++ fencepost for parameters

Write a function named rangeOfNumbers that accepts two integers as parameters and prints as console output the sequence of numbers between the two parameters, separated by commas and spaces. Print an increasing sequence if the first parameter's value is smaller than the second; otherwise, print a decreasing sequence. If the two numbers are the same, that number should be printed by itself. Here are some example calls to your function and the resulting expected output:

Call Console Output
rangeOfNumbers(2, 8); 2, 3, 4, 5, 6, 7, 8
rangeOfNumbers(18, 11); 18, 17, 16, 15, 14, 13, 12, 11
rangeOfNumbers(42, 42); 42
Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.