times table
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: times table

  1. #1
    Join Date
    Jan 2014
    Posts
    7

    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

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,838

    Re: times table

    So what part is giving you trouble? I would think a simple 2d array would do the trick
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jan 2014
    Posts
    7

    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...

  4. #4
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,838

    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
    Last edited by DataMiser; March 5th, 2014 at 12:33 PM.
    Always use [code][/code] tags when posting code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center