Hey guys I'm supposed to create this program for my c++ class but i am at a loss. i have been doing fine in the class up until now.
I am supposed to create a program that simulates a random walk that starts with position 0. If its odd it moves to the right (add one) if the random number is even it moves to the left (subtract 1).
A few other things to mention are that you probably should use std:: to scope instead of usingnamespace std; and if you really don't want to type std:: you should put using std::cout; inside your main function. It should be int main() not void main(). Proper indentation won't hurt. Lastly you should try and avoid system.
You should initialize and declare it inside of your integer list.
Important to comment your code as friendly advice and comment where your problem is. That way I/someone else can be more.
from
int num1, num2, num3, num4, i, rs=12345;
to (i.e.)
int i;
int num1 = 0, num2 =1, num3 =2, etc.
And use shorthand operators. //+=, -=
I also built a similar random code but for a dice game as an example give me a sec.
They can't use compound operators look at them closer.
How can i get it to show an asterisk in the middle along with the position its moved? you could use a for loop to output the spaces then an asterisk or you could use std::setw. There are many approaches you could have taken.
By the way that shouldn't even compile. Considering they are not class functions there is no way they can access class variables and modify them. It also seems a bit overkill using a class for something this small.
Alright guys looks like I'm going to go figure out how I can do this and make it happen but thank you everybody for all your help.
You have included iomanip why not make use of std::setw as I mentioned earlier
I am lol I figured that would be easier than a for loop the only problem I'm going to have is to get it to move to the left or right and show the position it moved.
std::setw(15)This should be num3 [edit]instead of 15[/edit]. Though you probably want to put line 13 inside of the for loop unless it is a linear movement.
When i do that I get this error: Run-Time Check Failure #3 - The variable 'num3' is being used without being initialized. With the option of break or continue.