944,117 Members | Top Members by Rank

Ad:
Apr 19th, 2007
0

Adding the sum of odd numbers. Please help

Expand Post »
I have been trying to figure this out for quite some time... Some help would be appreciated


intnumber = txtnum.Text
intcount = 1
Do While lngsum <= intnumber
intcount = intcount + lngsum
lngsum = lngsum + 2
Loop
lblsum.Caption = "The sum of the odd numbers is: " & intcount
Last edited by t3hfr3ak; Apr 19th, 2007 at 12:02 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
t3hfr3ak is offline Offline
22 posts
since Apr 2007
Apr 19th, 2007
0

Re: Adding the sum of odd numbers. Please help

Correct me if I'm wrong. The user enters a number and the app is supposed to add each odd number between 0 and the input? Your program, on the other hand, adds each even number less than or equal to the input then adds 1 to the total sum. To correct this, one way is that intcount = 1 should be lngsum = 1
Reputation Points: 26
Solved Threads: 5
Junior Poster
scudzilla is offline Offline
191 posts
since Mar 2007
Apr 19th, 2007
0

Re: Adding the sum of odd numbers. Please help

:o I got it
Option Explicit
Dim intnumber As Integer
Dim lngsum As Long
Dim intcount As Integer

Private Sub cmdcalc_Click()
intcount = 0
intnumber = txtnum.Text
lngsum = 1
Do While lngsum <= intnumber
intcount = intcount + lngsum
lngsum = lngsum + 2
Loop
lblsum.Caption = "The sum of the odd numbers is: " & intcount
End Sub

Private Sub txtnum_Change()
lblsum.Caption = "The sum of the odd numbers is: "
End Sub
Reputation Points: 10
Solved Threads: 0
Newbie Poster
t3hfr3ak is offline Offline
22 posts
since Apr 2007
Apr 19th, 2007
0

Re: Adding the sum of odd numbers. Please help

This will work just as well

lblsum.Caption = "The sum of the odd numbers is: " & round((intnumber / 2) + .1) ^ 2

Cheers

D
Reputation Points: 12
Solved Threads: 8
Junior Poster
davidcairns is offline Offline
114 posts
since Feb 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Drawing curves with Picbox.Line
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: suggestion please!!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC