![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
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 FunctionThanks. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
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 Functionnot 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! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 19
Rep Power: 0
![]() |
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.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
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! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |