
-----------------------------------
Jas
Sun Mar 27, 2005 10:24 pm

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.

-----------------------------------
Naveg
Sun Mar 27, 2005 10:27 pm


-----------------------------------
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
Sun Mar 27, 2005 10:31 pm


-----------------------------------
wow that was a quick reply!  so can you tell me what i should change to make it work?

-----------------------------------
Mr. T
Sun Mar 27, 2005 10:35 pm

Re: simple program help(real int problem)
-----------------------------------
answer := answer/2
it seems like ur trying to divide the answer by 2
so instead do..
answer:=answer div 2

-----------------------------------
Jas
Sun Mar 27, 2005 10:39 pm


-----------------------------------
yup that worked. thanks vladimir

-----------------------------------
Jas
Sun Mar 27, 2005 10:41 pm


-----------------------------------
oh ya, i missed pwned! :D  thanks pwned

-----------------------------------
Mr. T
Sun Mar 27, 2005 10:42 pm


-----------------------------------
any time  :wink:

-----------------------------------
Naveg
Sun Mar 27, 2005 10:43 pm


-----------------------------------
youre most welcome, good luck with turing and the world of programming, i'm sure you'll like it

-----------------------------------
Cervantes
Mon Mar 28, 2005 6:46 am

Re: simple program help(real int problem)
-----------------------------------
answer := answer/2
it seems like ur trying to divide the answer by 2
so instead do..
answer:=answer div 2
Better yet, use

answer := round (answer / 2)

so that we aren't always rounding down.

-----------------------------------
[Gandalf]
Mon Mar 28, 2005 5:09 pm


-----------------------------------
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.
