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

Username:   Password: 
 RegisterRegister   
 Help with Logo (Turtle Graphics)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ChuChun




PostPosted: Wed Apr 19, 2017 10:40 pm   Post subject: Help with Logo (Turtle Graphics)

I need to recreate the program Logo in turing, I can't figure out how to get the user's distance input

var direction : int := 0
var x, y : int
var input : string
var i : int := 1
var move : string := "move"
var left : string := "left"
var right : string := "right"
x := 300
y := 200

Draw.Dot (x, y, black)

%Procedure to face left
procedure Left
direction := direction + 90
if direction >= 360 then
direction := 0
end if
end Left

%Procedure to face right
procedure Right
direction := direction - 90
if direction = -90 then
direction := 270
end if
end Right

%Procedure to move forward depending on direction it is facing
procedure Move
var distance : int
if strintok (input(5..*)) then
distance := strint (input(5..*))
end if
if direction = 270 then
Draw.Line (x, y, x + distance, y, black)
elsif direction = 90 then
Draw.Line (x, y, x - distance, y, black)
x := x - distance
elsif direction = 180 then
Draw.Line (x, y, x, y - distance, black)
y := y - distance
else
Draw.Line (x, y, x, y + distance, black)
y := y + distance
end if

end Move




loop
get input : *

if input = move then
Move
elsif input = right then
Right
elsif input = left then
Left
end if
exit when input = "q"
end loop



Help me please.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Fri Apr 28, 2017 2:03 pm   Post subject: RE:Help with Logo (Turtle Graphics)

distance is an integer. It's as simple as writing 'get distance'. Note that if you input a string, the program will crash. There are ways around this, but we'll cross that bridge when we get there.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: