Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#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 :
HWB IO Formatting
Initial Vaue:
No of Iterations:
Update Size:
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:
PASSED!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started