Author |
Message |
yoimzuup
|
Posted: Sat Nov 13, 2004 9:51 pm Post subject: I need some help on turing... |
|
|
Try the code below first. The problem that im having is that it wouldn't bounce back up and then back down when it touches the top, etc. Im wondering if someone could help me fix this problem. Help would be accpreciated.
var change : int := 1
var row : int
var column : int
put "Enter the row"
get row
put "Enter the column"
get column
loop
setscreen ("nocursor")
locate (row, column)
put "*"
row := row + change
delay (200)
cls
if row = 25 then
row := row - change
end if
end loop |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Sat Nov 13, 2004 11:19 pm Post subject: (No subject) |
|
|
Reformatted. Please use code tags.
code: | var change : int := 1
var row : int
var column : int
put "Enter the row"
get row
put "Enter the column"
get column
loop
setscreen ("nocursor")
locate (row, column)
put "*"
row := row + change
delay (200)
cls
if row = 25 then
row := row - change
end if
end loop |
The asterisk starts off and descends until it gets to row 25, at which point it continues going down, but it also goes up one. The net effect is that it never goes anywhere.
What you want to do is, when the asterisk gets to the bottom of the screen, alter the "change". Do the same when it gets to the top of the screen. |
|
|
|
|
|
yoimzuup
|
Posted: Sat Nov 13, 2004 11:31 pm Post subject: (No subject) |
|
|
I can make it go back up but can't make it go on forever. I want it to run forever but I don't know how. Please help me.
code: | var change : int := 1
var row : int
var column : int
put "Enter the row"
get row
put "Enter the column"
get column
loop
setscreen ("nocursor")
locate (row, column)
put "*"
row := row + change
delay (20)
cls
if row = 25 then
loop
locate (row, column)
put "*"
row := row - change
delay (20)
cls
if row = 1 then
loop
locate (row, column)
put "*"
row := row + change
delay (20)
cls
end loop
end if
end loop
end if
end loop |
|
|
|
|
|
|
wtd
|
Posted: Sun Nov 14, 2004 12:17 am Post subject: (No subject) |
|
|
You're making it too hard.
Each time through your loop you clear the screen, draw the pixel, then subtract one from the row to make it go down.
So to make it go up without changing that subtraction, you would just change "change", right? |
|
|
|
|
|
yoimzuup
|
Posted: Sun Nov 14, 2004 12:48 am Post subject: (No subject) |
|
|
Sorry, Im getting really confused right now. I tried fixing it many times and I still can't get it right. I was just introduced to turing so Im a newbie. Can someone please fix the code for me?
Thanks |
|
|
|
|
|
wtd
|
Posted: Sun Nov 14, 2004 1:00 am Post subject: (No subject) |
|
|
I'm sorry. We sort of don't like to do people's homework for them. Short of that we'll do anything we can to help you, though.
And don't worry about being confused, you're a new programmer. Confusion is part of the process.
The key to beating confusion is knowing how to tackle problems. Plan out exactly what you need to do first. Attention to details is good. |
|
|
|
|
|
skier
|
Posted: Sun Nov 14, 2004 12:12 pm Post subject: (No subject) |
|
|
try this:
code: |
var r : int
var c : int
put "enter the row"
get r
put "enter the column"
get c
loop
loop
locate (r, c)
put "*"
r := r + 1
delay (50)
cls
exit when r = 24
end loop
if r = 24 then
r := r - 1
end if
loop
locate (r, c)
put "*"
r := r - 1
delay (50)
cls
exit when r = 1
end loop
if r = 1 then
r := r + 1
end if
end loop
|
if you have any questions, post |
|
|
|
|
|
wtd
|
Posted: Sun Nov 14, 2004 2:56 pm Post subject: (No subject) |
|
|
Skier, you're still working too hard.
Think about math. Think about equations. Factor out the common bits so you don't duplicate code unnecessarily. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mr. Glib
|
|
|
|
|
wtd
|
Posted: Sun Nov 14, 2004 3:04 pm Post subject: (No subject) |
|
|
Mr. Glib wrote: wtd wrote:
Think about math. Think about equations. Factor out the common bits so you don't duplicate code unnecessarily.
wtd!?! Are you serious! You mean to say that programming actually involves math!?!
Heh. Often really simple math, and mostly just the basic "math" thought process. Look at my regex tutorials for more examples of thinking like a mathematician in action. |
|
|
|
|
|
yoimzuup
|
|
|
|
|
zylum
|
Posted: Sun Nov 14, 2004 7:05 pm Post subject: (No subject) |
|
|
i believe this would be the easiest method:
code: | var r : int
var c : int
var dy := 1
put "enter the row"
get r
put "enter the column"
get c
loop
locate (r, c)
put "*"
r += dy
if r = 1 or r = maxrow - 1 then
dy *= -1
end if
delay (100)
cls
end loop |
|
|
|
|
|
|
wtd
|
Posted: Sun Nov 14, 2004 11:36 pm Post subject: (No subject) |
|
|
zylum wrote: i believe this would be the easiest method:
code: | var r : int
var c : int
var dy := 1
put "enter the row"
get r
put "enter the column"
get c
loop
locate (r, c)
put "*"
r += dy
if r = 1 or r = maxrow - 1 then
dy *= -1
end if
delay (100)
cls
end loop |
+10 bits. |
|
|
|
|
|
|