
-----------------------------------
atrain
Thu Mar 03, 2005 11:16 pm

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)

-----------------------------------
jamonathin
Fri Mar 04, 2005 6:59 am


-----------------------------------
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
Fri Mar 04, 2005 7:01 am


-----------------------------------
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
Fri Mar 04, 2005 1:04 pm


-----------------------------------
where is this tutorial that you speakith of?

-----------------------------------
Tony
Fri Mar 04, 2005 1:49 pm


-----------------------------------
where is this tutorial that you speakith of?
[url=http://www.compsci.ca/v2/viewtopic.php?t=6723]Internet -- same place where every other Turing tutorial is.

-----------------------------------
atrain
Fri Mar 04, 2005 4:44 pm


-----------------------------------
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
Fri Mar 04, 2005 5:18 pm


-----------------------------------
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. :)

-----------------------------------
atrain
Sun Mar 06, 2005 4:41 pm


-----------------------------------
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!!!

-----------------------------------
McKenzie
Sun Mar 06, 2005 4:43 pm


-----------------------------------
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
Sun Mar 06, 2005 5:52 pm


-----------------------------------
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
Sun Mar 06, 2005 7:53 pm


-----------------------------------
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
Sun Mar 06, 2005 8:18 pm


-----------------------------------
There shouldn't be any problem with 453 lines.  Probably you've got some really long lines.  Try splitting them up.

-----------------------------------
atrain
Thu Mar 10, 2005 10:03 pm


-----------------------------------
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..)
