Question: Hi, can someone help me code this program in c++ format with the output looking like the one shown? The behavior of a random walk

Hi, can someone help me code this program in c++ format with the output looking like the one shown?

Hi, can someone help me code this program in c++ format withthe output looking like the one shown? The behavior of a random

The behavior of a random walk can be modeled in code by creating a function to update a stored value by a random amount every time that function is called. For this problem, create a function called randWalk that takes 2 inputs: a stored oldValue and a range, where the range is the maximum number that the random update can be. Your function randWalk should match the following function declaration: int randWalk (int oldValue, int updateSize); Inside your function definition for randWalk, write the code for randWalk to take an integer value and modify it by a random value in the following manner: 1. Generate a random number between -updateSize and +updateSize 2. Calculate a newValue by adding your random number to oldValue 3. Check if newvalue is within the allowable range for your integer. a. If your newValue is greater than 255 , set it to 255 . b. If it is less than 0 , set it to 0 . 4. Return newValue To test this function, create a main() function that asks the user for: (1) an initial starting value initialValue inside the range of 0-255 (inclusive), (2) the number of values N to generate from your new function, and (3) the maximum update size for iterations. Check that the user enters a value in the range 0255 for the initial starting value, and print an error message if they do not, before continuing and asking them for the input again. You can assume that the user will give valid input for the number of iterations (>=0) and possible update size (>=0). Then, call randWalk ()N times and Example Output \#1 Example Output \#2 Note: Your output values will NOT be the same as those shown here. This is a random walk, so you should not get the same results every time you run your program. Make sure you seed rand() correctly

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!