|
-
Feb 25th, 2009, 10:33 PM
#1
Thread Starter
New Member
[2005] Pls help me
I have this teacher that doesn't offer any help and gives things that are not in the book. Even though my problem is simple I am also a beginner at this.
I'm having trouble with a loop the accumulates odd numbers but excludes the numbers input into the to input text boxes.
Say I put 1 in the lesser text box and 6 in the greater text box. How would I go about accumulating all odd numbers between 1 and 6. They would be 3 and 5 leaving me with a sum of 8 but im getting 9 because i can't exclude the inputs.
My code is
Code:
Private Sub calcBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcBtn.Click
Dim SumInteger As Integer = 0
Dim lesserInteger As Integer = 0
Dim greaterInteger As Integer = 100
With Me
lesserInteger = Integer.Parse(.lesserTB.Text)
greaterInteger = Integer.Parse(.greaterTB.Text)
Do While lesserInteger <= greaterInteger
SumInteger += lesserInteger
lesserInteger += 2
Loop
.answerlbl.Text = SumInteger.ToString("N")
End With
End Sub
-
Feb 26th, 2009, 01:49 AM
#2
Re: [2005] Pls help me
Code:
Private Sub calcBtn_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles calcBtn.Click
Dim total As Integer = 0
Dim start As Integer = Integer.Parse(lesserTB.Text)
Dim endnum As Integer = Integer.Parse(greaterTB.Text)
If start mod 2 = 0 Then start -= 1
Do While start < endnum - 2
start += 2
total += start
Loop
MessageBox.Show(total.ToString())
End Sub
-
Feb 26th, 2009, 03:08 AM
#3
Re: [2005] Pls help me
 Originally Posted by thenhemadecuic
I have this teacher that doesn't offer any help and gives things that are not in the book.
...
hehe..
I think he his doing a much bigger help to you in the long run. Every teacher teaches what is in the textbooks, but only a few go above it to take pains to get you something more.
-
Feb 28th, 2009, 12:09 AM
#4
Thread Starter
New Member
Re: [2005] Pls help me
Thanks that worked better then what i had figured out
-
Feb 28th, 2009, 04:15 AM
#5
New Member
Re: [2005] Pls help me
Hi,
You may simply wish to try something like this...
vb Code:
Private Sub calcBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcBtn.Click Dim SumInteger As Integer = 0 Dim lesserInteger As Integer = 0 Dim greaterInteger As Integer = 0 With Me lesserInteger = Integer.Parse(.lesserTB.Text) + 1 greaterInteger = Integer.Parse(.greaterTB.Text) - 1 For ctr As Integer = lesserInteger To greaterInteger Step 1 if ctr Mod 2 != 0 then sum = sum + ctr End If Next End With End Sub
Rahil Parikh
Live life like there is no tomorrow!!! 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|