Computer Science Canada Need Help adding a counter |
Author: | Murphman [ Thu Oct 29, 2009 1:13 pm ] | ||
Post subject: | Need Help adding a counter | ||
What is it you are trying to achieve? I created a guessing game and i am having trouble adding a counter in. so that when you guess the right number it will show you how many guess's it took you to get that number What is the problem you are having? it puts 0 where i want it to put number of guess it took Describe what you have tried to solve this problem i tried adding a var outside of the for loop and declaring it as 0 and making it so it goes up by one everytime the loop is ran. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using turing 4.1 |
Author: | DemonWasp [ Thu Oct 29, 2009 1:39 pm ] |
Post subject: | RE:Need Help adding a counter |
Your flow of control is very wrong. The code for incrementing your num variable will never be executed because it occurs immediately after an exit, which will take you out of the loop without executing anything further. It also never happens on incorrect guesses. |
Author: | Sited [ Sat Oct 31, 2009 3:35 pm ] | ||
Post subject: | RE:Need Help adding a counter | ||
All I can say is add more comments and make your variables more descriptive so whoever is reading your code will actually want to read it.. as for counter, you use variable += 1 or variable := variable + 1. And you have to put that inside the loop where you have to guess again. So basically what you can do is
|
Author: | B-Man 31 [ Sat Oct 31, 2009 7:10 pm ] | ||
Post subject: | RE:Need Help adding a counter | ||
why is it in a for loop, it should be in a regular loop, that will also make it easier to add a counter
|