Computer Science Canada Turing loop help |
Author: | munt4life [ Tue Oct 12, 2010 7:59 pm ] |
Post subject: | Turing loop help |
Hey could someone help me on these, i found them on a small quiz and found them tough. Thanks! 1. Create a program that gets ten numbers from the user and computes the average of the numbers. 2. Create a program that allows the user to try to guess a number from 1 to 1000. The number to be guessed will be randomly generated by your program. After each guess tell the user if the real number is higher of lower. If they guess the right number in 10 or fewer guesses tell them they did a good job, otherwise don't be as nice. |
Author: | Sur_real [ Tue Oct 12, 2010 9:46 pm ] | ||||
Post subject: | Re: Turing loop help | ||||
TURING!!!!!! It's been a while. Since I don't want to provide any direct answers... For 1. It's actually quite simple.
For 2. A little more tricky.
For the second question you can also opt to stop the program after a certain number tries *The code should be right and logical lol |
Author: | DanShadow [ Tue Oct 12, 2010 11:32 pm ] |
Post subject: | RE:Turing loop help |
Sur_real wrote: Since I don't want to provide any direct answers...
Lol, looks like you did his homework for him ![]() |
Author: | copthesaint [ Tue Oct 12, 2010 11:54 pm ] |
Post subject: | Re: Turing loop help |
Sur_real @ Tue Oct 12, 2010 wrote: TURING!!!!!! It's been a while.
Since I don't want to provide any direct answers... ........................................................................ ........................................................................ *The code should be right and logical lol Thats not turing. Good try though ![]() |
Author: | munt4life [ Wed Oct 13, 2010 6:08 am ] |
Post subject: | RE:Turing loop help |
I actually didnt want the answe but haha ok, that isnt turing ![]() |
Author: | DanShadow [ Wed Oct 13, 2010 7:04 am ] |
Post subject: | RE:Turing loop help |
I never said it was Turing ![]() That code/pseudo-code can be directly translated into Turing by simply interpreting what each line would be in Turing. Really very little difference from giving him the code in Turing, still gives him the answer, lol. |
Author: | JamesV [ Wed Oct 13, 2010 8:16 am ] |
Post subject: | RE:Turing loop help |
Well the first program , you don't even need a loop, unless you use an array, but it can be done with simple commands easily (Even though it would be shorter using an array) |
Author: | DanShadow [ Wed Oct 13, 2010 8:32 am ] |
Post subject: | RE:Turing loop help |
I'd still recommend using a loop, but definitely an array would be a bit more efficient, but the end result is the same. |
Author: | Sur_real [ Wed Oct 13, 2010 12:18 pm ] |
Post subject: | Re: RE:Turing loop help |
DanShadow @ Wed Oct 13, 2010 7:04 am wrote: I never said it was Turing
![]() That code/pseudo-code can be directly translated into Turing by simply interpreting what each line would be in Turing. Really very little difference from giving him the code in Turing, still gives him the answer, lol. yeah...bad pseudo-code while you're at it ![]() |
Author: | chrisbrown [ Wed Oct 13, 2010 5:33 pm ] |
Post subject: | Re: RE:Turing loop help |
DanShadow @ Wed Oct 13, 2010 8:32 am wrote: I'd still recommend using a loop, but definitely an array would be a bit more efficient, but the end result is the same.
An array would use 10 times more memory than is needed, and provides nothing in terms of CPU efficiency. An explicit loop counter isn't needed either. That's what for loops are for. |
Author: | Sur_real [ Wed Oct 13, 2010 7:35 pm ] |
Post subject: | Re: RE:Turing loop help |
chrisbrown @ Wed Oct 13, 2010 5:33 pm wrote: DanShadow @ Wed Oct 13, 2010 8:32 am wrote: I'd still recommend using a loop, but definitely an array would be a bit more efficient, but the end result is the same.
An array would use 10 times more memory than is needed, and provides nothing in terms of CPU efficiency. An explicit loop counter isn't needed either. That's what for loops are for. O_o that's true...why didn't I think of that? ![]() |
Author: | Krocker [ Tue Dec 07, 2010 5:41 pm ] |
Post subject: | RE:Turing loop help |
srry for askin this stupid question, but what is for loop? |
Author: | ProgrammingFun [ Tue Dec 07, 2010 7:44 pm ] |
Post subject: | RE:Turing loop help |
A for loop is basically a counted loop in which the loop will exit after a certain number of repetitions...this is an efficient way of preventing infinite loops |
Author: | andrew. [ Tue Dec 07, 2010 8:21 pm ] | ||
Post subject: | RE:Turing loop help | ||
In Turing a for loop looks like this:
Basically, it's a type of loop that will loop around a certain amount of times. In the above case, I made it loop 10 times by making it count from 1 to 10 using the variable i to store the numbers. |