Computer Science Canada times table |
Author: | Tallguy [ 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? |
Author: | [Gandalf] [ 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...
And your nested for loop will look something like...
Also, your setscreen() call, height array, and math variable are all not being used, so you should remove them. |
Author: | Tallguy [ 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 ![]() |
Author: | Jessica359 [ Fri Apr 11, 2008 9:36 am ] |
Post subject: | RE:times table |
y do u always post thing before i do ![]() |
Author: | Tallguy [ Fri Apr 11, 2008 9:42 am ] |
Post subject: | RE:times table |
'cause i'm special |
Author: | gitoxa [ 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. |
Author: | Tallguy [ 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 |
Author: | gitoxa [ 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 |
Author: | [Gandalf] [ 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.
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. |
Author: | CodeMonkey2000 [ Sat Apr 12, 2008 10:52 am ] | ||
Post subject: | Re: times table | ||
Or you can make your code more obfuscated with:
By the way, didn't someone already make a similar thread? |
Author: | OneOffDriveByPoster [ 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):
|
Author: | Tallguy [ 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? |