Computer Science Canada

Table of Squares

Author:  illu45 [ Thu Mar 10, 2005 8:58 pm ]
Post subject:  Table of Squares

Hey guys,

I'm trying to make a table that lists a number, makes a space and then lists a sqaure. What I have so far is this:
code:

put "Number", "      ", "Sqaure"
for i : 1 .. 50
    if i**2 < 100 then
        put i, "              ", i ** 2
        delay (100)
    elsif i ** 2 >= 100 then
        put i, "             ", i ** 2
        delay (100)
    end if
end for


The only problem with this is that I want it to move over to the right instead of scrolling. After numerous failed attempts with the locate command, I decided to scrap it adn try to only use the " ", as you can see above, unfortunately, I can't seem to get it to wrap around that way.

Any ideas would be greatly appretiated,
illu45

Author:  person [ Thu Mar 10, 2005 9:13 pm ]
Post subject: 

can u explain wat u mean by "wrap"?

Author:  ssr [ Thu Mar 10, 2005 9:33 pm ]
Post subject: 

use something like this
code:

put "x":3
8)

Author:  ssr [ Thu Mar 10, 2005 10:13 pm ]
Post subject: 

code:
for i:1..16
put i:5..
end for
for i:1..16
put i**2:5..
end for
for i:1..maxcol
put"_"..
end for
for i:17..32
put i:5..
end for
for i:17..32
put i**2:5..
end for
for i:1..maxcol
put"_"..
end for
for i:33..48
put i:5..
end for
for i:33..48
put i**2:5..
end for
for i:1..maxcol
put"_"..
end for
for i:49..50
put i:5..
end for
put " "
for i:49..50
put i**2:5..
end for

These r such shameful codes
soo long
ppl probably do it in 5 lines
but this just shows the format ...... I think Shocked Confused 8)

Author:  Cervantes [ Fri Mar 11, 2005 4:31 pm ]
Post subject: 

How about this?
Turing:

var output : string
var row := 2
var col := 1
put "Number", "      ", "Sqaure"
for i : 1 .. 50
    output := intstr (i) + "**2 = " + intstr (i ** 2)
    if col + length (output) < maxcol then
        if col + length (output) + length (" ~~ ") < maxcol then
            output += " ~~ "
        end if
        locate (row, col)
        put output ..
        col += length (output)
    else
        row += 1
        col := 1
    end if
    delay (100)
end for

Author:  illu45 [ Fri Mar 11, 2005 6:23 pm ]
Post subject: 

That works pretty well, except that the Numbe/Square headings and the numbers don't line up to well... I finished it up at school today, but don't have it on me (at home now), I'll post it on Monday.

Author:  illu45 [ Tue Mar 15, 2005 6:35 pm ]
Post subject: 

Here's the code, as promised:

code:

%Question 6
var row, col : int
row := 3
col := 1
put "Number", "      ", "Sqaure"
for i : 1 .. 50
    if i ** 2 < 100 then
        locate (row, col)
        row := row + 1
        put i, "              ", i ** 2
        if row = 25 then
            row := 3
            col := col + 30
            locate (row, col)
            put "Number", "      ", "Sqaure"
        end if
        delay (100)
    elsif i ** 2 >= 100 then
        locate (row, col)
        put i, "             ", i ** 2       
        row := row + 1
        if row = 25 then
            row := 3
            col := col + 30
            locate (1, col)
            put "Number", "      ", "Sqaure"
        end if
        delay (100)
    end if
end for

Author:  ssr [ Tue Mar 15, 2005 7:11 pm ]
Post subject: 

illu45 wrote:
Here's the code, as promised:

code:

%Question 6
var row, col : int
row := 3
col := 1
put "Number", "      ", "Sqaure"
for i : 1 .. 50
    if i ** 2 < 100 then
        locate (row, col)
        row := row + 1
        put i, "              ", i ** 2
        if row = 25 then
            row := 3
            col := col + 30
            locate (row, col)
            put "Number", "      ", "Sqaure"
        end if
        delay (100)
    elsif i ** 2 >= 100 then
        locate (row, col)
        put i, "             ", i ** 2       
        row := row + 1
        if row = 25 then
            row := 3
            col := col + 30
            locate (1, col)
            put "Number", "      ", "Sqaure"
        end if
        delay (100)
    end if
end for

lol thats what u wanted... Very Happy

Author:  ssr [ Tue Mar 15, 2005 7:47 pm ]
Post subject: 

another code
Very Happy
code:
var c:=1
var r:=1
for i:1..50
r+=1
locate (r,c)
put i:2, "  ----->",i**2:4," |"
if r =23 then
c+=16
r:=1
end if
end for

Author:  Flikerator [ Wed Mar 16, 2005 12:09 pm ]
Post subject: 

ssr wrote:
another code
Very Happy
code:
var c:=1
var r:=1
for i:1..50
r+=1
locate (r,c)
put i:2, "  ----->",i**2:4," |"
if r =23 then
c+=16
r:=1
end if
end for


You knocked the shiz outa that code lolz


: