d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Nested Loop Project > Final Projects
Add Reply New Topic New Poll
Member
Posts: 1,234
Joined: Feb 25 2012
Gold: 10,198.00
Jun 2 2013 04:40pm
So our teacher assigned us 3 VB projects, I got one. But needed help with another
Goals: nested loops

It's making a mutiplication table, like this
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

I know the User Input is...
2 numbers, between 1-20 (inclusive), which will decide the numbers for the top and sides.

Need help starting this please

Edit: Using VB Express 2012

This post was edited by Stickzz on Jun 2 2013 04:41pm
Member
Posts: 1,234
Joined: Feb 25 2012
Gold: 10,198.00
Jun 2 2013 04:54pm


Thus far, don't know how to go from here
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 2 2013 05:31pm
Start with 1 loop if you can't figure out two loops. make it go from 1 to 5 horizontally. then change 5 to user input.

then add a second loop to go vertically
Member
Posts: 1,234
Joined: Feb 25 2012
Gold: 10,198.00
Jun 2 2013 05:41pm
Quote (carteblanche @ Jun 2 2013 07:31pm)
Start with 1 loop if you can't figure out two loops. make it go from 1 to 5 horizontally. then change 5 to user input.

then add a second loop to go vertically


Thanks.
having some trouble getting it to actually go horizontal and vertical.


so far..
Quote
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ListBox1.Items.Clear()
        Dim TopC As Integer = TextBox1.Text
        Dim SideR As Integer = TextBox2.Text

        For counter = TopC To SideR
            ListBox1.Items.Add(counter)
        Next
    End Sub


All it's doing is say.. I put 1 in to the first textbox, 10 into the second, it will print number 1-10, but if I do 10 and 10, it prints 10

This post was edited by Stickzz on Jun 2 2013 05:46pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 2 2013 06:00pm
clearly, if you tell the loop to start at 10 and finish at 10, it will only execute once. your inputs do not belong in the same loop, they are your endpoints on each of your loops.

i think it will help you a lot if you first start without the loop. copy/paste all your lines of code until it looks perfect. then you can turn it into loops. turn one of them into a loop at a time. if it broke your output, then adjust until it's right. i think that'll help you get more comfortable with loops.

of course, dont go crazy with all 100 points. start with a 1x1 matrix. then add code to make it 2x2. then 2x5. then 3x6. etc until you get comfortable with the pattern to see how to use a loop

and why are you using a list box?

This post was edited by carteblanche on Jun 2 2013 06:10pm
Member
Posts: 1,234
Joined: Feb 25 2012
Gold: 10,198.00
Jun 2 2013 06:14pm
Quote (carteblanche @ Jun 2 2013 08:00pm)

and why are you using a list box?

where should I output it?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 2 2013 06:28pm
Quote (Stickzz @ Jun 2 2013 08:14pm)
where should I output it?


i would have used a textbox, but it's your call.
Member
Posts: 1,234
Joined: Feb 25 2012
Gold: 10,198.00
Jun 2 2013 07:23pm
Quote (carteblanche @ Jun 2 2013 08:28pm)
i would have used a textbox, but it's your call.


I haven't used a texbox as the output for any of the projects ive done, its mostly a messagebox or listbox

edit: Just had a thought, is there any way I'd be able to make it output to a messagebox? And make it have the set columns/rows.

Edit2: Epiphany happened, lol. no need for help guys!

This post was edited by Stickzz on Jun 2 2013 07:34pm
Member
Posts: 10,812
Joined: Oct 15 2009
Gold: Locked
Warn: 20%
Jun 3 2013 12:53am
from abduck:

i dont see how this problem took this long to solve lol.

Code

irb(main):007:0> 10.times do |x|
irb(main):008:1*   10.times do |y|
irb(main):009:2*     print "#{x*y} "
irb(main):010:2>   end
irb(main):011:1>   print "\n"
irb(main):012:1> end
0 0 0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7 8 9
0 2 4 6 8 10 12 14 16 18
0 3 6 9 12 15 18 21 24 27
0 4 8 12 16 20 24 28 32 36
0 5 10 15 20 25 30 35 40 45
0 6 12 18 24 30 36 42 48 54
0 7 14 21 28 35 42 49 56 63
0 8 16 24 32 40 48 56 64 72
0 9 18 27 36 45 54 63 72 81
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll