Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 14th, 2006, 4:20 PM   #1
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
Question Help - Get the product of the numbers between 1 and n?

How can I change this code to get the product of the numbers between 1 and a variable n. Here's the code, and I can just get the n's square.

    Function product(ByVal n As Double, ByRef i As Double)
        Dim a As Double
        For i = 1 To n
            a = n * i
        Next
        Return a
    End Function

Thanks.
dwizzle13 is offline   Reply With Quote
Old Dec 14th, 2006, 5:18 PM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
well, right now you are reseting the varible "a" to a new number everytime your loop runs.

you need to add the value to a, here's how i would do it.

Function product(ByVal n As Double, ByRef i As Double)
       Dim a As Double
       a = 0
       for i = 1 To n
              a = a + (i*n)
       Next
       Return a
End Function

not sure if that's what you are looking for. Also, this looks like homework....please don't let it be homework, mainly because posting homework questions is against the forum rules.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Dec 14th, 2006, 7:33 PM   #3
dwizzle13
Newbie
 
Join Date: Oct 2006
Posts: 19
Rep Power: 0 dwizzle13 is on a distinguished road
thanks

Thanks, no, it's for myself. I'm trying to learn vb from an old book, but I didn't know what to do.
dwizzle13 is offline   Reply With Quote
Old Dec 15th, 2006, 10:09 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
ah ok, cool...for i minute there i thought i was doing your homework (we get a lot of people trying to get us to do home work questions).
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI Script - change product display jess Perl 3 Jul 12th, 2006 5:25 PM
Median/Mode in arrays? {Need help} Java|Tera Java 27 Nov 29th, 2005 10:50 AM
Reading in multiple numbers wingz198 C++ 2 Oct 14th, 2005 1:45 PM
Prime Numbers Konnor C++ 6 Sep 12th, 2005 6:46 PM
Assignment of numbers to variables without asking Haz C# 26 May 23rd, 2005 10:30 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC