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

Username:   Password: 
 RegisterRegister   
 mystery program...
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
program_x




PostPosted: Mon May 07, 2007 2:11 pm   Post subject: mystery program...

basically, i'm trying to make a program, that holds a series of numbers, then get rid of some and add some more etc.

well i have a var called count which is the number that is the value of the number which is added to the line, and will go up by one after it has been added to the line

what i want to know is why it will 'skip' sometimes as high as 6 at a time ex. count = 25 and next pass through the loop, count = 31

here is my code
code:

class theQueue
    export enter, leave, display, listupper
    var list : flexible array 1 .. 0 of int
    var listupper : int := 0
    proc enter (enternum : int) %enter
        if listupper < 17 then
            new list, upper (list) + 1
            list (upper (list)) := enternum
            listupper := upper (list)
        end if
    end enter

    fcn leave : real %leave (real so if the result is not an integer,
        %array is empty)
        var temp : int
        if upper (list) > 0 then
            temp := lower (list)
            for i : 1 .. upper (list) - 1
                list (i) := list (i + 1)
            end for
            new list, upper (list) - 1
            listupper := upper (list)
            result intreal (temp)
        else
            result .1
        end if
    end leave

    proc display %display
        if upper (list) > 0 then
            for i : 1 .. upper (list)
                put list (i)
            end for
        else
            put "nothing in list"
        end if
    end display
end theQueue

%%%%%MAINLINE%%%%%
var queue : ^theQueue
new queue

var count : int := 0
var last : int := 0
var temp : real
loop
    case Rand.Int (1, 5) of
        label 1 :
            count += 1
            queue -> enter (count)
        label 2 :
            temp := queue -> leave
        label 3 :
        label 4 :
            count += 1
            queue -> enter (count)
            count += 1
            queue -> enter (count)
        label 5 :
            temp := queue -> leave
            temp := queue -> leave
    end case
    cls
    exit when last = 601
    queue -> display
    locate (3, 5)
    put last ..
    locate (4, 5)
    put count ..
    delay (250)
    last += 1
end loop
queue -> display
put "\nDone"
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: