You are on page 1of 1

#include<iostream>

#include<iomanip>
#include<cstdlib>
#include<ctime>

using namespace std;

int main()
{

int d;
int position = 99; // Initial it is at 40
int init_position = position;
// for producing different random number
// each time program runs
srand(static_cast<unsigned int>(time(0)));
unsigned i;

for( i=1; i <= 10000; ++i)


{
d = (rand()%5)-2;
position = position + d;
if( position > 100 ) // 100 represents the end point
position = 100 - position;
if( position < 0) // 0 be the initial point
position = 100 - abs(position);
}

cout << "Initial position is " << init_position << endl;


cout << "Final position after 10,000 iterations is " << position << endl;
}

You might also like