
-----------------------------------
Tallguy
Thu Apr 10, 2008 11:24 am

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?

-----------------------------------
[Gandalf]
Thu Apr 10, 2008 1:01 pm

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...
for i : 1 .. 5
    put i * 5
end for

And your nested for loop will look something like...
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
Fri Apr 11, 2008 9:31 am

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 :shock:

-----------------------------------
Jessica359
Fri Apr 11, 2008 9:36 am

RE:times table
-----------------------------------
y do u always post thing before i do ;) lol

-----------------------------------
Tallguy
Fri Apr 11, 2008 9:42 am

RE:times table
-----------------------------------
'cause i'm special

-----------------------------------
gitoxa
Fri Apr 11, 2008 10:11 am

Re: times table
-----------------------------------
Suggestions:

This is what you have

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
Fri Apr 11, 2008 12:43 pm

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
Fri Apr 11, 2008 1:23 pm

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

-----------------------------------
[Gandalf]
Sat Apr 12, 2008 9:40 am

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.

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
Sat Apr 12, 2008 10:52 am

Re: times table
-----------------------------------
Or you can make your code more obfuscated with:
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
Sat Apr 12, 2008 1:05 pm

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):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
Mon Apr 14, 2008 7:27 am

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 , thanks a lot everyone

can i make it better?
