#include<iostream>
#include<iomanip>
int main()
{
std::srand(static_cast<unsigned>(std::time(nullptr)));
int iterations;
std::cout << "How many iterations would you like(<0 = quit): ";
std::cin >> iterations;
const int initialPosition = 5;
int currentPosition = initialPosition;
for(int i = 0; i < iterations; ++i)
{
int random = std::rand();
if(random % 2 == 0) //random & 1 == 1 -- even
{
++currentPosition;
}
else
{
--currentPosition;
}
std::cout << "Iteration: " << std::setw(4) << i+1 << ':' << std::setw(currentPosition) << '*' << std::endl;
}
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGlvbWFuaXA+CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6c3JhbmQoc3RhdGljX2Nhc3Q8dW5zaWduZWQ+KHN0ZDo6dGltZShudWxscHRyKSkpOwogICAgCiAgICBpbnQgaXRlcmF0aW9uczsKICAgIHN0ZDo6Y291dCA8PCAiSG93IG1hbnkgaXRlcmF0aW9ucyB3b3VsZCB5b3UgbGlrZSg8MCA9IHF1aXQpOiAiOwogICAgc3RkOjpjaW4gPj4gaXRlcmF0aW9uczsKICAgIAogICAgY29uc3QgaW50IGluaXRpYWxQb3NpdGlvbiA9IDU7CiAgICBpbnQgY3VycmVudFBvc2l0aW9uID0gaW5pdGlhbFBvc2l0aW9uOwogICAgCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgaXRlcmF0aW9uczsgKytpKQogICAgewogICAgICAgIGludCByYW5kb20gPSBzdGQ6OnJhbmQoKTsKICAgICAgICAKICAgICAgICBpZihyYW5kb20gJSAyID09IDApIC8vcmFuZG9tICYgMSA9PSAxIC0tIGV2ZW4KICAgICAgICB7CiAgICAgICAgICAgICsrY3VycmVudFBvc2l0aW9uOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICAtLWN1cnJlbnRQb3NpdGlvbjsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgc3RkOjpjb3V0IDw8ICJJdGVyYXRpb246ICIgPDwgc3RkOjpzZXR3KDQpIDw8IGkrMSA8PCAnOicgPDwgc3RkOjpzZXR3KGN1cnJlbnRQb3NpdGlvbikgPDwgJyonIDw8IHN0ZDo6ZW5kbDsKICAgIH0KICAgIAp9