I have no idea how to begin to program this...

Create a program that simulates a random walk. It starts with
position 0. If a generated random number is an odd number, it moves to
the right (add 1), if the random number is an even number, it moves to
the left (subtract 1).
Step 1 : Set random number seed to 1 followed by last 4 digits of your
student ID. Receive the number of iterations to be executed.
Step 2 : Display the current location (See the output example).
Step 3 : Generate a random number. If a generated random number is an
odd number, move to the right (add 1), if the random number is an even
number, move to the left (subtract 1).
Step 4 : Repeat step 2 and step 3 for user specified times.
The easiest way to begin is to write the hello-world program. Make at least some attempt at writing the program, then post it along with a specific thing you are stuck on.
Last edited on
#include<iostream>
#include<iomanip>
Using namespace std;

Int num1, rs = 14161, I, num2, num3, num4;

Void main()
{
Cout << " Please enter the number iterations to be executed: ";
Cin >> num 1;

Num4 = 0
For (I = 0; I < num1 + 1; I++)

Cout << I << ": ";

Srand(rs);
Num2 = Rand();

If (num2 % 2 = 1)
{
Num3 = num4 - 1;
Cout << num3;
}
Else
{
Num3 = num4 + 1;
Cout << num3;
}

}
What I have so far but obviously it's next to nothing...
It's a start. Edit your post and write [code] before your code and [/code] after your code, this will give syntax highlighting.

Firstly, it looks like whatever you were typing in capitalized the first letter of each line - that's no good, C++ is case-sensitive.

Second, the return type of the main function needs to be int, not void.

Third, why are you using global variables? You don't need to for this program, and global variables shouldn't be used in 99% of cases anyway. Just move the definitions to the start of the main function.

Fix all that and repost your code - I'll help more from there.
Last edited on
Topic archived. No new replies allowed.