Computer Science Canada

Getting the last kink out of my program about running arrays

Author:  Chimaera [ Sun Feb 08, 2004 2:57 pm ]
Post subject:  Getting the last kink out of my program about running arrays

My program should run but doesn't run on account of an error that I cannot assign a subscript to arrays >.> I don't get why it doesn't work and also the other 2 errors are due to the same array issue. It says missing time compression value. Please help me thanks!

code:
var num : int
var distance : int
var clubdist : int

get distance
get num
var arrayofclubs : 1 .. num of int
for i : 1 .. num
    get arrayofclubs(i)
end for
for i : 1 .. num
    clubdist := clubdist + arrayofclubs(i)
end for
if clubdist = distance then
    put "Roberta wins in ", num
else
    put "Roberta acknowledges defeat"
end if

Author:  Paul [ Sun Feb 08, 2004 3:09 pm ]
Post subject: 

Um thats not how you do an array, isn't it:
code:

var arrayofclubs : array 1 .. num of int

oh yea
code:

var clubdist : int :=0

or whatever, or else it has no value. and can't be used in:
code:

    clubdist := clubdist + arrayofclubs(i)

Author:  Chimaera [ Sun Feb 08, 2004 3:35 pm ]
Post subject: 

Thanks for your help. It works now! yay


: