Computer Science Canada

Help with virticle array out put

Author:  - IzAk - [ Mon May 28, 2007 11:32 am ]
Post subject:  Help with virticle array out put

can anyone change this to out put virtically:

function CreateVerticalV2 : array 1 .. 6 of int
var X : array 1 .. 6 of int
var found : boolean
X (1) := Rand.Int (2, 9)

for i : 2 .. 6
loop
X (i) := Rand.Int (2, 9)
found := false
for j : 1 .. i - 1
if X (i) = X (j) then
found := true
exit
end if
end for
exit when found = false
end loop
end for
result X
end CreateVerticalV2

Author:  Clayton [ Mon May 28, 2007 11:34 am ]
Post subject:  RE:Help with virticle array out put

Considering you're not outputting anything at all, it makes it kind of hard to see where you're going wrong. All your function does is return a value, assuming you're coding with good style, you'll be outputting in your main loop.

Author:  - IzAk - [ Mon May 28, 2007 11:37 am ]
Post subject:  RE:Help with virticle array out put

function CreateVerticalV2 : array 1 .. 6 of int % (no parameters needed)
var X : array 1 .. 6 of int
var found : boolean
X (1) := Rand.Int (2, 9) % pick any random for the first one

for i : 2 .. 6
loop
X (i) := Rand.Int (2, 9) % pick a random number
found := false % assume it hasn't been used before
for j : 1 .. i - 1 % check all previous numbers to see if a duplicate exists
if X (i) = X (j) then
found := true % bad - must try a new random
exit
end if
end for
exit when found = false
end loop
end for
result X
end CreateVerticalV2

% MAIN
var hN :array 1..6 of int
hN := CreateHorizontalV2
for i : 1 .. 6
put hN (i) : 3 ..
end for
put ""

Author:  Clayton [ Mon May 28, 2007 11:45 am ]
Post subject:  RE:Help with virticle array out put

here's your mainline:

Turing:

% MAIN
var hN :array 1..6 of int
hN := CreateHorizontalV2
for i : 1 .. 6
    put hN (i) : 3 ..
end for
put ""


and here's my version of your mainline:

Turing:

% MAIN
var hN :array 1..6 of int
hN := CreateVerticalV2
for i : 1 .. 6
    put hN (i) : 3
end for
put ""


What did I change to fix it? (We'll leave the fact that CreateHorizontalV2 was not declared out for now).

Author:  - IzAk - [ Mon May 28, 2007 11:48 am ]
Post subject:  RE:Help with virticle array out put

you took away the two .. damit, i always get caught by something simplistic!


: