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

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




PostPosted: Thu Apr 10, 2008 11:24 am   Post subject: times table

i'm doing a program to create a times table for a usr defined range this is what i have


%Alex van der Mout

setscreen ("graphics:600;500")

var number, math : int
put "What do you the table to up to? (max 12) " ..
get number
put ""
var height : array 1 .. number of real

for i : 0 .. number
put "" : 4, i ..
end for

put ""
for o : 1 .. number
put ""
put "" : 4, o
end for


how do i actually do the math for user defined?
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Thu Apr 10, 2008 1:01 pm   Post subject: RE:times table

Well, you are already keeping track of two variables, i and o, so use those in a nested for loop and output the multiplication.

Your multiplication will look something like...
code:
for i : 1 .. 5
    put i * 5
end for


And your nested for loop will look something like...
code:
for a : 1 .. 10
    for b : 1 .. 10
        put "multiplication here"
    end for
end for


Also, your setscreen() call, height array, and math variable are all not being used, so you should remove them.
Tallguy




PostPosted: Fri Apr 11, 2008 9:31 am   Post subject: Re: times table

i thought of doing it a different way, but the spacing for the double + triple digits are really messed up

srry for how long it is Shocked



12x12x2.t
 Description:

Download
 Filename:  12x12x2.t
 Filesize:  7.95 KB
 Downloaded:  98 Time(s)

Jessica359




PostPosted: Fri Apr 11, 2008 9:36 am   Post subject: RE:times table

y do u always post thing before i do Wink lol
Tallguy




PostPosted: Fri Apr 11, 2008 9:42 am   Post subject: RE:times table

'cause i'm special
gitoxa




PostPosted: Fri Apr 11, 2008 10:11 am   Post subject: Re: times table

Suggestions:

This is what you have
code:

put "" : 4, i ..

You're outputting spaces, and giving them a field width. Instead of that, play around with giving your numbers field width instead.


About your arrays, isn't the computer a calculator? Is it really neccesary to store all that information...


Did you even read the post from [Gandalf]? Nested loops are your friend.
Tallguy




PostPosted: Fri Apr 11, 2008 12:43 pm   Post subject: RE:times table

yay i no but we have do do our arrays in this order,

"play around with giving your numbers field width instead."

i don't exactly know wat u meamn by this
gitoxa




PostPosted: Fri Apr 11, 2008 1:23 pm   Post subject: Re: times table

Arrays in what order?

This is taken from the turing help doc

Statement Output Notes
put 121 : 5 bb121 % Width 5; b is blank
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sat Apr 12, 2008 9:40 am   Post subject: Re: times table

You're hard coding values into multiple arrays instead of doing simple multiplication, that's not a very good way of doing it at all.

code:
var num : int
put "Up to what number? " ..
get num
for a : 1 .. num
    for b : 1 .. num
        put a * b : 4 ..
    end for
    put skip
end for

This is much easier to understand, no?

Or do you mean that your assignment requires you to use arrays? Even so, you could assign your computed values to the appropriate element in the array and use that.
CodeMonkey2000




PostPosted: Sat Apr 12, 2008 10:52 am   Post subject: Re: times table

Or you can make your code more obfuscated with:
Turing:
var ans : int
put "Up to what number? "
get ans
for x : 0 .. ans * ans - 1
    locate (x mod ans + 1, x div ans * 4 + 1)
    put (x mod ans + 1) * (x div ans + 1)
end for


By the way, didn't someone already make a similar thread?
OneOffDriveByPoster




PostPosted: Sat Apr 12, 2008 1:05 pm   Post subject: Re: times table

If arrays are required, use them and avoid multiplication (and if I was the teacher and I asked for arrays, using this is idea would be required for full marks):
Turing:
var num : int
put "Up to what number?"
get num
var row : array 1 .. num of int
for a : 1 .. num
    row (a) := a
    put a : 4 ..
end for
put ""
for a : 2 .. num
    for b : 1 .. num
        row (b) += b
        put row (b) : 4 ..
    end for
    put ""
end for
Tallguy




PostPosted: Mon Apr 14, 2008 7:27 am   Post subject: Re: times table

Thanks for all the feed back, i used ur ideas and made my orignal better, now it is 39 lines instead of 400 <woot>, thanks a lot everyone

can i make it better?



Unit 3_12x12_Alex van der Mout.t
 Description:
My final times table

Download
 Filename:  Unit 3_12x12_Alex van der Mout.t
 Filesize:  1.02 KB
 Downloaded:  88 Time(s)

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  [ 12 Posts ]
Jump to:   


Style:  
Search: