-
times table
Hi folks,
need some help to create array using iteration – the array once populated will
be representative of the grid below.
need use a function to create the array.
need to use the array to perform multiplication of numbers between 1 and 5 (2 numbers
must be entered by textboxes), if the user enters in 2 and 2,it must look
up the array to obtain the correct answer.
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25
any help would be much appreciated
thanks
-
Re: times table
So what part is giving you trouble? I would think a simple 2d array would do the trick
-
Re: times table
At the moment I just have:
Dim timesTable(5, 5) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For y As Integer = 0 To 5
For x As Integer = 0 To 5
timesTable(y, x) = (x + 1) * (y + 1)
Next
Next
End Sub
No idea what to do next...
-
Re: times table
Well that looks like it would populate the array you just need to reference the right element to get the value you are looking for
You just have to use the values entered by the user
e.g.
Answer=TimesTable(TextBox1.Text,TextBox2.Text)
So if the user entered 3 in the first box and 4 in the second it would be accessing array element TimesTable(3,4) Which in your code above would contain the result of 3*4 which of course would be 12
Of course you need to test and make sure that the user entered a number within bounds and you need to convert the entry from string to int before you use the values as your array index but that is the basic idea
Edit: On another note you really should not be adding +1 to either value in your loops else you will throw off everything by one and your element 5,5 will contain 36 instead of 25
If you do add the one then you will have to subtract 1 from what the user enters to get the correct element