reset password
Author Message
lakerfan94
Posts: 143
Posted 20:21 Sep 29, 2015 |

I'm having trouble with the second lab exercise given today. I declared a variable that will hold the number of guesses. In the guess function, I increment that variable. Yet, the value for the variable remains at 0(the value I initialized the variable to), even when I call the bigger and the smaller functions. Can someone help me?

Last edited by lakerfan94 at 20:21 Sep 29, 2015.
rabbott
Posts: 1649
Posted 21:06 Sep 29, 2015 |

It would help if you provide more detail about how you increment the variable. How about a transcript of the input and output.

gjackso2
Posts: 24
Posted 21:11 Sep 29, 2015 |

Are you working off of the code from Exercise 1? In that case, your guess function might not be getting called each guess.

I have it working except for the formatting of the ending phrase.

Last edited by gjackso2 at 21:21 Sep 29, 2015.
hal255
Posts: 51
Posted 22:51 Sep 29, 2015 |

LAKERFAN94: Did you also set the value to the new incremented value?

GJACKSO2: Took a while for me to get it, but in last example on very top of page 6 from the book helped me a lot.

 

Good luck.

hal255
Posts: 51
Posted 22:58 Sep 29, 2015 |

LAKERFAN94: Sorry, meant to say set the variable to the new incremented value. Not sure if there is a better way, but that's how I got it to work.

lakerfan94
Posts: 143
Posted 23:01 Sep 29, 2015 |

For incrementing the variable , I'm using the add1 function. For example, my variable is called "numGuesses" and in the guess function, I would state (add1 numGuesses). I just recently changed the guess function where all I do is just set the value for a variable to hold the guess, excluding the part of counting the number of guesses. I recently tweaked the code in which I have a separate function called "addGuesses" that has the add1 function call in it. This function "addGuesses" I then call in the bigger, smaller, and start function. For sure, I know that I'm getting the correct guesses. The main problem is that the variable to count the number of guesses isn't working.

Attached to this reply, I have a screenshot of the results. In this trial, 25 is my desired number. For now, the (correct) function returns the value of the variable "numGuesses". The problem though is that it returns 0.

Attachments:
lakerfan94
Posts: 143
Posted 23:03 Sep 29, 2015 |

@HAL255 I barely saw your reply right now. Ok, I'll try your approach.

lakerfan94
Posts: 143
Posted 23:12 Sep 29, 2015 |

@HAL255 and everyone else who replied, thank you! I got the issue figured out. Really appreciate it!