Computer Science Canada simple program help(real int problem) |
| Author: | Jas [ Sun Mar 27, 2005 10:24 pm ] |
| Post subject: | simple program help(real int problem) |
ok this is a noobish question. how do u make this program run: var answer: int get answer answer := answer/2 for i : 1..answer put "Hi" end for the error i get is the "answer/2" part. which is because u cant divide an integer by 2 i guess. so i did var answer: real get answer answer := answer/2 for i : 1..answer put "Hi" end for now i get an error at the "for i : 1..answer" part. I'm a turing newbi, plz help. |
|
| Author: | Naveg [ Sun Mar 27, 2005 10:27 pm ] |
| Post subject: | |
the second one wont work because the for loop has to count in integers, so if answer is a real it wont work the first part will only work if the number inputted in an even number |
|
| Author: | Jas [ Sun Mar 27, 2005 10:31 pm ] |
| Post subject: | |
wow that was a quick reply! so can you tell me what i should change to make it work? |
|
| Author: | Mr. T [ Sun Mar 27, 2005 10:35 pm ] | ||
| Post subject: | Re: simple program help(real int problem) | ||
Jas wrote: answer := answer/2
it seems like ur trying to divide the answer by 2 so instead do..
|
|||
| Author: | Jas [ Sun Mar 27, 2005 10:39 pm ] |
| Post subject: | |
yup that worked. thanks vladimir |
|
| Author: | Jas [ Sun Mar 27, 2005 10:41 pm ] |
| Post subject: | |
oh ya, i missed pwned! |
|
| Author: | Mr. T [ Sun Mar 27, 2005 10:42 pm ] |
| Post subject: | |
any time |
|
| Author: | Naveg [ Sun Mar 27, 2005 10:43 pm ] |
| Post subject: | |
youre most welcome, good luck with turing and the world of programming, i'm sure you'll like it |
|
| Author: | Cervantes [ Mon Mar 28, 2005 6:46 am ] | ||||
| Post subject: | Re: simple program help(real int problem) | ||||
Pwned wrote: Jas wrote: answer := answer/2
it seems like ur trying to divide the answer by 2 so instead do..
Better yet, use
so that we aren't always rounding down. |
|||||
| Author: | [Gandalf] [ Mon Mar 28, 2005 5:09 pm ] |
| Post subject: | |
Yes, 'div' is only good for things like this if you are going to use 'mod' (remainder) too. I suggest looking at all of the above mentioned solutions in the Turing Help file F9, F10, F11. |
|