Computer Science Canada

Times table 2

Author:  Jessica359 [ Fri Apr 11, 2008 9:31 am ]
Post subject:  Times table 2

Just to add on to the times table,this is it finished but we need it to be in a straightline. How can i do that?

code:


setscreen ("graphics:1000;500")


var number, math : int
put ""
var top : array 1 .. 12 of real

for i : 0 .. 12
    put "" : 7, i ..
end for
put ""



%%%%%%%%%%%%%%

var top2 : array 1 .. 13 of real := init (1,1,2,3,4,5,6,7,8,9,10,11,12)

for b : 1 .. 13
    put "   " : 7, top2(b) ..
end for
put ""


var top3 : array 1 .. 13 of real := init (2,2,4,6,8,10,12,14,16,18,20,22,24)

for c : 1 .. 13
    put "       " : 5, top3(c) ..
end for
put ""


var top4 : array 1 .. 13 of real := init (3,3,6,9,12,15,18,21,24,28,32,36,40)

for d : 1 .. 13
    put "       " : 5, top4(d) ..
end for
put ""


var top5 : array 1 .. 13 of real := init (4,4,8,12,16,20,24,28,32,36,40,44,48)

for e : 1 .. 13
    put "       " : 5, top5(e) ..
end for
put ""


var top6 : array 1 .. 13 of real := init (5,5,10,15,20,25,30,35,40,45,50,55,60)

for f : 1 .. 13
    put "       " : 5, top6(f) ..
end for
put ""


var top7 : array 1 .. 13 of real := init (6,6,12,18,24,30,36,42,48,54,60,66,72)

for g : 1 .. 13
    put "       " : 5, top7(g) ..
end for
put ""



var top8 : array 1 .. 13 of real := init (7,7,14,21,28,35,42,49,56,63,70,77,84)

for h : 1 .. 13
    put "       " : 5, top8(h) ..
end for
put ""

var top9 : array 1 .. 13 of real := init (8,8,16,24,32,40,48,56,64,72,80,88,96)

for i : 1 .. 13
    put "       " : 5, top9(i) ..
end for
put ""



var top10 : array 1 .. 13 of real := init (9,9,18,27,36,45,54,63,72,81,90,99,108)

for j : 1 .. 13
    put "       " : 5, top10(j) ..
end for
put ""



var top11 : array 1 .. 13 of real := init (10,10,20,30,40,50,60,70,80,90,100,110,120)

for k : 1 .. 13
    put "       " : 5, top11(k) ..
end for
put ""



var top12 : array 1 .. 13 of real := init (11,11,22,33,44,55,66,77,88,99,110,121,132)

for l : 1 .. 13
    put "       " : 5, top12(l) ..
end for
put ""



var top13 : array 1 .. 13 of real := init (12,12,24,36,48,60,72,84,96,108,120,132,144)

for m : 1 .. 13
    put "       " : 5, top13(m) ..
end for
put ""


thnxs Smile

Author:  andrew. [ Fri Apr 11, 2008 9:44 am ]
Post subject:  Re: Times table 2

Use colons instead of spaces in the put command.

Author:  gitoxa [ Fri Apr 11, 2008 9:45 am ]
Post subject:  Re: Times table 2

You do realize everything you just did it do-able in 7 lines?

Author:  Tallguy [ Fri Apr 11, 2008 9:59 am ]
Post subject:  RE:Times table 2

i have to know the same thing jess, check out my times table (the topic is called 'times table'), i need help too

Author:  Jessica359 [ Fri Apr 11, 2008 10:47 am ]
Post subject:  RE:Times table 2

in 7 lines...? seriously?

Author:  StealthArcher [ Fri Apr 11, 2008 10:53 am ]
Post subject:  RE:Times table 2

Yes, completely possible and easily done:

1. Think for loop, plus locate.
2. You can use a for loops number to multiply your root.
3. Using two for loops, you can use locate to set a row, and column.


Think and read the helps, try it than come back.

Author:  gitoxa [ Fri Apr 11, 2008 11:05 am ]
Post subject:  Re: Times table 2

Using locate just makes things complicated. Field width is a good solution, but try using it on the numbers, rather then adding spaces.
But to correct myself, 11 lines, not 7. I had it written in 7, but it wasn't quite right. Other than that...

Nested loops
; loops within loops.

Author:  StealthArcher [ Fri Apr 11, 2008 11:07 am ]
Post subject:  Re: Times table 2

code:
for t: 1..13
for e: 1..13
locate(t,(e*4))
put t*e
end for
end for


6 lines, booyah

Author:  Jessica359 [ Fri Apr 11, 2008 12:59 pm ]
Post subject:  RE:Times table 2

awesome
thanks Smile

Author:  Jessica359 [ Fri Apr 11, 2008 1:14 pm ]
Post subject:  RE:Times table 2

WAIT! One problem...
we need to use arrays for our program.

Author:  gitoxa [ Fri Apr 11, 2008 1:14 pm ]
Post subject:  Re: Times table 2

Where's your 1 times table?
And the whole point was to get them to do the work theirselves, not do it for them.

Author:  Jessica359 [ Fri Apr 11, 2008 1:24 pm ]
Post subject:  RE:Times table 2

it doesn't matter if we get them to do it themselves or display them on the screen, it just has to be done with arrays and needs to be in straight colums and rows, i was told to use if statements but it takes 4ever to rearrange them all in straight lines, so ya.. Smile

Author:  CodeMonkey2000 [ Fri Apr 11, 2008 1:40 pm ]
Post subject:  RE:Times table 2

You have to use arrays? This is a stupid assignment. A lot of assignments I see seem pretty stupid and pointless. This isn't even a practical application of arrays. It makes your code redundant.

Author:  Sean [ Fri Apr 11, 2008 3:37 pm ]
Post subject:  Re: Times table 2

Arrays should not be used for multiplication tables, regardless of what the teacher says.

What you are doing is using ranges from 1 - 13, the for loops do this more effectively.

The arrays should be used when collecting data for the same variable, such as first names, there would be numerous of them, depending on how many you collect, and it stores each input to the variable.

Tell your teacher, that for loops are better then arrays in this situation, and see if the requirements can be modified.

Author:  Jessica359 [ Fri Apr 11, 2008 6:14 pm ]
Post subject:  RE:Times table 2

Ok i'll mention it to him.
I know the assignments are stupid and pointless but hey if thats what he wants for a passing mark then thats what we have to give him.
thnx though Smile

Author:  A.J [ Fri Apr 11, 2008 7:54 pm ]
Post subject:  Re: Times table 2

make a 2-D array to store the times table of all numbers from 1..12 like this:
Turing:

var timestable : array 1..12,1..12 of int

for i:1..12
   for j:1..12
      timestable(i,j) := i*j
   end for
end for

then, you can just use the locate thing again but this time it gets easier: since you're dealing with arrays, you can just use a for loop or a variable to keep track of the ith component of timestable(i,j), sine j just ranges from 1..12 !

sry if I was late Sad

Author:  CodeMonkey2000 [ Fri Apr 11, 2008 9:30 pm ]
Post subject:  Re: Times table 2

Bah single dimensional array enables you to be more 1337.
Turing:

var table : array 0 .. 143 of int
for x : 0 .. 11
    for y : 0 .. 11
        table (y * 12 + x) := (x + 1) * (y + 1)
    end for
end for
for x : 0 .. 143
    locate (x mod 12 + 1, x div 12 * 4 + 1)
    put table (x mod 12 * 12 + x div 12)
end for


EDIT: This program can be done in 4 lines.
Turing:

for x : 0 .. 143
    locate (x mod 12 + 1, x div 12 * 4 + 1)
    put (x mod 12 + 1) * (x div 12 + 1)
end for

Author:  OneOffDriveByPoster [ Fri Apr 11, 2008 10:44 pm ]
Post subject:  Re: Times table 2

CodeMonkey2000 @ Fri Apr 11, 2008 9:30 pm wrote:
Bah single dimensional array enables you to be more 1337.
1337-ness shouldn't be the point. This can help you avoid having arrays of pointers for dynamic 2-D arrays in C/C++.

Author:  CodeMonkey2000 [ Fri Apr 11, 2008 10:55 pm ]
Post subject:  RE:Times table 2

I never use multidimensional dynamic arrays. I always represent my data in a single dimensional array, it makes it easier to manage and clean up.

EDIT: The whole thing in 8 lines, still trying to get it in 7 Razz.
Turing:
var table : array 0 .. 143 of int
for x : 0 .. 143
    table (x mod 12 * 12 + x div 12) := (x mod 12 + 1) * (x div 12 + 1)
end for
for x : 0 .. 143
    locate (x mod 12 + 1, x div 12 * 4 + 1)
    put table (x mod 12 * 12 + x div 12)
end for

Author:  gitoxa [ Sat Apr 12, 2008 12:04 am ]
Post subject:  Re: Times table 2

Just use one for loop. Razz


: