Posted: 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.
Sponsor Sponsor
Naveg
Posted: Sun Mar 27, 2005 10:27 pm Post subject: (No 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
Jas
Posted: Sun Mar 27, 2005 10:31 pm Post subject: (No subject)
wow that was a quick reply! so can you tell me what i should change to make it work?
Mr. T
Posted: 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..
code:
answer:=answer div 2
Jas
Posted: Sun Mar 27, 2005 10:39 pm Post subject: (No subject)
yup that worked. thanks vladimir
Jas
Posted: Sun Mar 27, 2005 10:41 pm Post subject: (No subject)
oh ya, i missed pwned! thanks pwned
Mr. T
Posted: Sun Mar 27, 2005 10:42 pm Post subject: (No subject)
any time
Naveg
Posted: Sun Mar 27, 2005 10:43 pm Post subject: (No subject)
youre most welcome, good luck with turing and the world of programming, i'm sure you'll like it
Sponsor Sponsor
Cervantes
Posted: 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..
code:
answer:=answer div 2
Better yet, use
code:
answer := round (answer / 2)
so that we aren't always rounding down.
[Gandalf]
Posted: Mon Mar 28, 2005 5:09 pm Post subject: (No 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.