Author |
Message |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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?
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
12x12x2.t |
Filesize: |
7.95 KB |
Downloaded: |
98 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Jessica359
![](http://compsci.ca/v3/uploads/user_avatars/7434636574818b0e9b7877.gif)
|
Posted: Fri Apr 11, 2008 9:36 am Post subject: RE:times table |
|
|
y do u always post thing before i do lol
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: Fri Apr 11, 2008 9:42 am Post subject: RE:times table |
|
|
'cause i'm special
|
|
|
|
|
![](images/spacer.gif) |
gitoxa
![](http://compsci.ca/v3/uploads/user_avatars/125344263047f801d546bcb.jpg)
|
Posted: Fri Apr 11, 2008 10:11 am Post subject: Re: times table |
|
|
Suggestions:
This is what you have
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.
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
gitoxa
![](http://compsci.ca/v3/uploads/user_avatars/125344263047f801d546bcb.jpg)
|
Posted: 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
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
[Gandalf]
![](http://compsci.ca/v3/uploads/user_avatars/189297994e4c716fec7f1.png)
|
Posted: 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.
|
|
|
|
|
![](images/spacer.gif) |
CodeMonkey2000
|
Posted: 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?
|
|
|
|
|
![](images/spacer.gif) |
OneOffDriveByPoster
|
Posted: 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 |
|
|
|
|
|
![](images/spacer.gif) |
Tallguy
![](http://compsci.ca/v3/uploads/user_avatars/515706924539b443d32a6e.gif)
|
Posted: 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?
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
Unit 3_12x12_Alex van der Mout.t |
Filesize: |
1.02 KB |
Downloaded: |
88 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
|