Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Multiplication table
Author Message
Punde

Posted: 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
...

Tony

Posted: 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
Tony's programming blog. DWITE - a programming contest.
Punde

Posted: 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

Posted: 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
Tony's programming blog. DWITE - a programming contest.
Punde

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

Oh I see, Thank you very much
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 5 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: