Sunday, August 2, 2009

Function question C++?

This is part of my function code where I eval. a random # and det. if the horse should advance 1 space. When I call the fun. 3 times, it doesn't execute properly, can somebody please tell me what's wrong w/ my code.





if(rollt %26gt; 50){


horsepos++;


cout%26lt;%26lt;"Your horse moved 1 space"%26lt;%26lt;endl%26lt;%26lt;endl;


}


else


cout%26lt;%26lt;"Your horse moved 0 spaces"%26lt;%26lt;endl%26lt;%26lt;endl;


























cout%26lt;%26lt;num_horse%26lt;%26lt;"|";








for (int horsepost = 1; horsepost %26lt;= horsepos; horsepost++){


cout%26lt;%26lt;"-";








}


//horsepost++;


cout%26lt;%26lt;"H";





for (int i = 0; i %26gt; horsepos - TRACK_LENGHT ; i--)


cout%26lt;%26lt;"-";


cout%26lt;%26lt;"|";

Function question C++?
Dude, i have no idea what that does, the code looks ok nothing seems to be wrong. have you tried using the debugger in visual stuidios to run through the code and check the variables as you go to see what is happeing to the values.





to propperly check this out you need to email me all your code adn i can look at it but this is not enough.





also the most important thing with programming is readability, use one new line istead of loads adn use your tabs for code scope!
Reply:I see a bug with this line:





for (int i = 0; i %26gt; horsepos - TRACK_LENGHT ; i--)





This loop will usually not run, since 0 is not %26gt; horsepos-TRACK_LENGTH





Instead, you want to initialize i to horsepos - TRACK_LENGTH and count down towards zero.


No comments:

Post a Comment