Computer Science Canada Counting the number of false Boolean expressions in a loop? |
Author: | gayden [ Fri Feb 20, 2015 10:12 am ] | ||||
Post subject: | Counting the number of false Boolean expressions in a loop? | ||||
Making a program where Turing generates a Rand.Int and user has to guess the number, if they get it right I want the program to tell them how many tries it took them to get the correct answer. Here's what I have so far:
Currently the variable 'times' has no value, so if you wish to run this you'll have to remove the declaration of times with nothing after it and the use of it in line 8. Is there a function in turing I can use to do this? Addittionally, I am making this one:
I think my error is similar to the first program, but I am not sure. Any help is appreciated. |
Author: | Tony [ Fri Feb 20, 2015 1:39 pm ] | ||||||||
Post subject: | RE:Counting the number of false Boolean expressions in a loop? | ||||||||
A more obvious problem is that you have incomplete lines of code
Otherwise yes, you need to initialize variable values. Otherwise in code such as
What should it print? It can't be known. Assigning a value first:
will resolve that ambiguity. |
Author: | gayden [ Fri Feb 20, 2015 4:34 pm ] | ||||||||
Post subject: | Re: RE:Counting the number of false Boolean expressions in a loop? | ||||||||
Tony @ Fri Feb 20, 2015 1:39 pm wrote: A more obvious problem is that you have incomplete lines of code
Otherwise yes, you need to initialize variable values. Otherwise in code such as
What should it print? It can't be known. Assigning a value first:
will resolve that ambiguity. gayden @ Fri Feb 20, 2015 10:12 am wrote: Currently the variable 'times' has no value, so if you wish to run this you'll have to remove the declaration of times with nothing after it and the use of it in line 8. I know I have to give the variables values, but how do I get them to count the number of times 'sum' is written? |
Author: | Tony [ Fri Feb 20, 2015 5:18 pm ] | ||
Post subject: | Re: RE:Counting the number of false Boolean expressions in a loop? | ||
gayden @ Fri Feb 20, 2015 4:34 pm wrote: how do I get them to count the number of times 'sum' is written?
Have another counter variable.
|
Author: | gayden [ Tue Feb 24, 2015 9:19 am ] | ||||
Post subject: | Re: RE:Counting the number of false Boolean expressions in a loop? | ||||
Tony @ Fri Feb 20, 2015 5:18 pm wrote: gayden @ Fri Feb 20, 2015 4:34 pm wrote: how do I get them to count the number of times 'sum' is written?
Have another counter variable.
I believe I solved it.
Any problems with this one? |
Author: | Tony [ Tue Feb 24, 2015 1:31 pm ] |
Post subject: | RE:Counting the number of false Boolean expressions in a loop? |
Looks good to me. |