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

Username:   Password: 
 RegisterRegister   
 Removing an item in an array
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
atrain




PostPosted: Thu Mar 03, 2005 11:16 pm   Post subject: Removing an item in an array

i have to make a program which keeps track of things... I want things to be added and subtracted...

i hear a flexible array can let the array be added to, but can i delete arrayvar (2) and have everything else shift down??

im willing to move everything down, then delete the last one 2...


so how would i go about doing this? (adding + subtracting)
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Fri Mar 04, 2005 6:59 am   Post subject: (No subject)

code:
colorback (black)
color (white)
var file, maxnum : int := 10
var numbers : array 1 .. maxnum of int
var choice : string
for i : 1 .. maxnum
    numbers (i) := i * 3
end for
proc table
    cls
    for i : 1 .. maxnum
        locate (i, 1)
        put i, ". ", numbers (i)
    end for
end table
loop
    table
    put "Select a file number"
    get file
    put "What do you want to do, (w)rite, (d)elete, (q)uit?"
    get choice
    if choice = "w" then
        put "Enter a number"
        get numbers (file)
    elsif choice = "d" then
        if file not= maxnum then
            for i : file .. maxnum - 1
                numbers (i) := numbers (i + 1)
            end for
        end if
        numbers (maxnum) := 0
    else
        exit
    end if
end loop

Also look under tutorials under high score for more help on this.
Bacchus




PostPosted: Fri Mar 04, 2005 7:01 am   Post subject: (No subject)

read the flexible array tutorial on how to delete certain parts of it. its by Cervantes and he explain how to do that very well
atrain




PostPosted: Fri Mar 04, 2005 1:04 pm   Post subject: (No subject)

where is this tutorial that you speakith of?
Tony




PostPosted: Fri Mar 04, 2005 1:49 pm   Post subject: (No subject)

atrain wrote:
where is this tutorial that you speakith of?

Internet -- same place where every other Turing tutorial is.
atrain




PostPosted: Fri Mar 04, 2005 4:44 pm   Post subject: (No subject)

k, i see how to do it... thanks all!!!

1 other question: if i set new Array, current - 1

then it will properly delete an item??
Tony




PostPosted: Fri Mar 04, 2005 5:18 pm   Post subject: (No subject)

Exactly. If you need to get rid of an item in an array, just swap it with the last element and decrease the size by one. Smile
atrain




PostPosted: Sun Mar 06, 2005 4:41 pm   Post subject: (No subject)

yup it works fine... Thanx soo much


now only problem is my program is so huge, it doesnt have enougf memory to indent!!!
stupid wine!!!
Sponsor
Sponsor
Sponsor
sponsor
McKenzie




PostPosted: Sun Mar 06, 2005 4:43 pm   Post subject: (No subject)

Turing will also stop indenting if you have even a single line that is too long. Check for that before you give up on the auto-indent.
Bacchus




PostPosted: Sun Mar 06, 2005 5:52 pm   Post subject: (No subject)

copy selections of the code and paste them into a new turing file to indent it then just copy and paste that back into the main file. always did that at school and worked just fine
atrain




PostPosted: Sun Mar 06, 2005 7:53 pm   Post subject: (No subject)

by ine that is too long, do you mean like a loop / if statment inside a loop inside a loop and on and on, so that the indent would be huge

or

the line has 2 much text on it, and i have to split it up if possible???

i manualy indented it this time, but my code will just continue growing... i got rid of all big lines...
my program is 453 lines long...
Cervantes




PostPosted: Sun Mar 06, 2005 8:18 pm   Post subject: (No subject)

There shouldn't be any problem with 453 lines. Probably you've got some really long lines. Try splitting them up.
atrain




PostPosted: Thu Mar 10, 2005 10:03 pm   Post subject: (No subject)

ive split up long lines...

im pritty sure it has to do with the fact that im on wine...

i wish theyed make a version of turing for linux already (i hear there is one, but not sure how resent it is..)
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  [ 13 Posts ]
Jump to:   


Style:  
Search: