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

Username:   Password: 
 RegisterRegister   
 Table of Squares
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
illu45




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
person




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

can u explain wat u mean by "wrap"?
ssr




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

use something like this
code:

put "x":3
8)
ssr




PostPosted: Thu Mar 10, 2005 10:13 pm   Post subject: (No 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)
Cervantes




PostPosted: Fri Mar 11, 2005 4:31 pm   Post subject: (No 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
illu45




PostPosted: Fri Mar 11, 2005 6:23 pm   Post subject: (No 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.
illu45




PostPosted: Tue Mar 15, 2005 6:35 pm   Post subject: (No 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
ssr




PostPosted: Tue Mar 15, 2005 7:11 pm   Post subject: (No 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
Sponsor
Sponsor
Sponsor
sponsor
ssr




PostPosted: Tue Mar 15, 2005 7:47 pm   Post subject: (No 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
Flikerator




PostPosted: Wed Mar 16, 2005 12:09 pm   Post subject: (No 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
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  [ 10 Posts ]
Jump to:   


Style:  
Search: