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

Username:   Password: 
 RegisterRegister   
 Times table 2
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Jessica359




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




PostPosted: Fri Apr 11, 2008 9:44 am   Post subject: Re: Times table 2

Use colons instead of spaces in the put command.
gitoxa




PostPosted: 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?
Tallguy




PostPosted: 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
Jessica359




PostPosted: Fri Apr 11, 2008 10:47 am   Post subject: RE:Times table 2

in 7 lines...? seriously?
StealthArcher




PostPosted: 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.
gitoxa




PostPosted: 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.
StealthArcher




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




PostPosted: Fri Apr 11, 2008 12:59 pm   Post subject: RE:Times table 2

awesome
thanks Smile
Jessica359




PostPosted: Fri Apr 11, 2008 1:14 pm   Post subject: RE:Times table 2

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




PostPosted: 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.
Jessica359




PostPosted: 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
CodeMonkey2000




PostPosted: 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.
Sean




PostPosted: 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.
Jessica359




PostPosted: 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
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 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: