Question: #include #include #include #include / / Include for std::numeric _ limits / / Function for the random walk int randWalk ( int oldValue, int updateSize
#include
#include
#include
#include Include for std::numericlimits
Function for the random walk
int randWalkint oldValue, int updateSize
int randomChange std::randupdateSize updateSize;
int newValue oldValue randomChange;
if newValue
newValue ;
else if newValue
newValue ;
return newValue;
int main
std::srandstd::timenullptr; Seed the random number generator
int initialValue, iterations, updateSize;
Get user input for initial value with validation
while true
std::cout "Please enter an initial integer value in the range : ;
std::cin initialValue;
if std::cin.fail initialValue initialValue
std::cin.clear; Clear error flags
std::cin.ignorestd::numericlimits::max
; Discard bad input
std::cout "Value must be between and Please enter an initial value in the range : std::endl;
else
break; Valid input received, exit loop
Get user input for number of iterations
std::cout "Please enter the desired number of iterations: ;
std::cin iterations;
Get user input for the update size
std::cout "Please enter the size of each possible update for each iteration: ;
std::cin updateSize;
Perform the random walk with updated output formatting
for int i ; i iterations; i
initialValue randWalkinitialValue updateSize;
std::cout "Value at iteration # i is: initialValue std::endl;
return ;
HWB Compilation Test
COMPILATION SUCCESSFUL!!
HWB Testcase
Initial Vaue:
No of Iterations:
Update Size: pm
Your Output
Please enter an initial integer value in the range : Please enter the desired number of iterations: Please enter the size of each possible update for each iteration: Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Program Exit Succesfully!!
HWB Testcase
Initial Vaue:
No of Iterations:
Update Size: pm
Your Output
Please enter an initial integer value in the range : Please enter the desired number of iterations: Please enter the size of each possible update for each iteration: Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Value at iteration # is:
Program Exit Succesfully!!
HWB Invalid Input
Input Sequence:
Please enter an initial integer value in the range : Value must be between and Please enter an initial value in the range :
Please enter an initial integer value in the range : Value must be between and Please enter an initial value in the range : Value must be between and Please enter an initial value in the range : Value must be between and Please enter an initial value in the range : Please enter the desired number of iterations: Please enter the size of each possible update for each iteration:
FAILED!!
Test Failed: False is not true :
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
