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

Username:   Password: 
 RegisterRegister   
 Multiplication table
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Punde




PostPosted: Wed Feb 12, 2003 2:56 pm   Post subject: Multiplication table

Hello there,
I just joined this forum because I think it will help me a lot in Turing, which is what I am learning at the moment, anyways I have a question.
I am trying to do a multiplication table that displays the multiplication numbers from 1 to 19, however I don't know how to actually multiply them using for loops.
I have the following code:
code:

setscreen ( "text:25;90" )
put "      "..
for i:1..19
put i:4..
end for
put ""
put repeat ("-", 82)..

put ""
for a: 1..19
put a:4, "|"
end for


THe table has to look something like this:
-- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 1 2 3
2 2 4
3 3
4 4
5
6
7
8
9
...
and so on. Can anyone please help me with this? Thanks.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Feb 12, 2003 3:50 pm   Post subject: (No subject)

basically you next a forloop inside another forloop like this

code:

for r:1..19
    for c:1..19
    put r*c:4, "|"..
    end for
put ""
end for


For each of 19 rows (for r) there will be 19 columns (for c). In that space we put the product of the row number * column number

the put "" at the end of inside loop makes a new line so we move on to the next row.

You'll be using nested loops in many of your future programs Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Punde




PostPosted: Thu Feb 13, 2003 1:17 pm   Post subject: (No subject)

Thanks, but with the code you gave me I only get the actual multiplication but not the numbers on the top with the -------, nor the line on the left with the |. Can you help me with this little part?? Thx.
Tony




PostPosted: Thu Feb 13, 2003 1:49 pm   Post subject: (No subject)

for that you can use your own code...

there shouldn't be any probem of adding the top part to it. Just copy your code and place it in front of nested loops.

Now if you do a little modification to the nested loops, you can also draw a vetrical line in font of the table.

paste a line of code to put the numbers and | right after for r:1..19

where R would be your number.

code:

%YOUR CODE PART BELOW
put "      "..
for i:1..19
put i:4..
end for
put ""
put repeat ("-", 82)..

%MY CODE PART BELOW
for r:1..19
put r:4,"|"..  %<--- add this
    for c:1..19
    put r*c:4, "|"..
    end for
put ""
end for
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Punde




PostPosted: Thu Feb 13, 2003 1:55 pm   Post subject: (No subject)

Oh I see, Thank you very much Smile
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  [ 5 Posts ]
Jump to:   


Style:  
Search: