Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 simple program help(real int problem)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jas




PostPosted: 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
Sponsor
sponsor
Naveg




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Sun Mar 27, 2005 10:39 pm   Post subject: (No subject)

yup that worked. thanks vladimir
Jas




PostPosted: Sun Mar 27, 2005 10:41 pm   Post subject: (No subject)

oh ya, i missed pwned! Very Happy thanks pwned
Mr. T




PostPosted: Sun Mar 27, 2005 10:42 pm   Post subject: (No subject)

any time Wink
Naveg




PostPosted: 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
Sponsor
sponsor
Cervantes




PostPosted: 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]




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: