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

Username:   Password: 
 RegisterRegister   
 can somone edit these
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
a random person




PostPosted: Fri Nov 25, 2005 5:53 pm   Post subject: can somone edit these

i have a couple of eronious programs and i need somone to help
code:

%flashcards
var a, b, u, x, t : int
x = 0
for t : 1 .. 10
    put t
    delay (100)
    cls
    loop
        randint (a, 1, 9)
        randint (b, 1, 9)
        put a, "+", b
        get u
        if a + b < u then
            put "game over, your score is ", x
        elsif a + b > u then
            put "game over, your score is ", x
        else
            x := x + 1
            exit when a + b < u or a + b > u
        end if
    end loop
end for
if t = 10 then
    put "you ran out of time, your score is", x
else
end if


there is another one aswell
code:

var minute, hour : int
minute := 0
hour := 0
for second : 1 .. 60000
    put hour,":",minute,":",second
    delay (1000)
    cls
    if second = 60 then
        put minute + 1, ":", second - 60
    else
    end if
    if minute = 60 then
        put hour + 1, ":" ,minute - 60
    else
    end if
end for

if some one can help me i will be great!
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Fri Nov 25, 2005 7:07 pm   Post subject: (No subject)

you need to ask a question to get any help Wink
a random person




PostPosted: Sat Nov 26, 2005 8:44 am   Post subject: (No subject)

sry about that, first post and all Embarassed . the first one is a flash cards
program where they have 1 second to respond with the answer and the
other one is just a count up clock. with both of these I ran into some
logic problems that i can't work around Sad so, can anyone help me?
a random person




PostPosted: Sat Nov 26, 2005 1:45 pm   Post subject: (No subject)

guess what i have another one if anyone can curve this line it would be amasing
code:

var x,y:int
x:=maxx div 2
y:=0
for i :1..319
x:=x-1
y:=y+1
drawdot (x,y,12)
delay (20)
end for
if x=0 then
x:=x-1
else
end if
[Gandalf]




PostPosted: Sat Nov 26, 2005 2:10 pm   Post subject: (No subject)

Take a look at all the changes I have made in the last program, and see if you understand them.

Turing:
var x : int
var y, iy : real
x := maxx div 2
y := 0
iy := +0.1
for i : 1 .. 319
    x -= 1
    y += iy
    iy += 0.005
    Draw.Dot (x, round (y), 12)
    Time.DelaySinceLast (20)
end for

1. iy is how much the y coordinate increases every iteration of the loop, that value increase after it is added to y. This causes the curve.
2. you must round y when you are passing it to Draw.Dot() (drawdot()), because that procedure needs an integer, not a decimal number.
3. x -= 1 is the same thing as x := x - 1
4. use Time.DelaySinceLast() instead of delay(), since it works the same on all computers.
5. Please indent your program, at least use "F2".

As for your other programs, they seem to have logic errors in them, think them through and you should get the right answer. Thing step by step, try to follow what the program does.
[Gandalf]




PostPosted: Sat Nov 26, 2005 7:38 pm   Post subject: (No subject)

Yes, yes, please put replys in the topic which you posted in originally.

Hacker Dan wrote:
and has a poor subject name.

I don't know about a poor subject name though Wink.

Well, think about it, for that program you have it so that if second = 60 then... do whatever needed for when the seconds are over a minute. The thing is, what happens when there are 61 seconds? It goes back since second > 60, you need to take that into consideration. Solve that problem on your own, and try to figure out what is wrong with the other program as well. I, or anyone else, won't give you the exact answers, we can only help occasionally.[/quote]
milz




PostPosted: Sun Nov 27, 2005 11:38 am   Post subject: (No subject)

Yo here is ur correct code. hav fun..

Sad
%flashcards
var a, b, u, x : int
x := 0
for t : 1 .. 10
put t
delay (100)
cls
loop
randint (a, 1, 9)
randint (b, 1, 9)
put a, "+", b
get u
if a + b < u then
put "game over, your score is ", x
elsif a + b > u then
put "game over, your score is ", x
else
x := x + 1
exit when a + b < u or a + b > u
end if
end loop
end for
if b = 10 then
put "you ran out of time, your score is", x
else
end if
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  [ 7 Posts ]
Jump to:   


Style:  
Search: