473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Exponential Looping

Got a problem in my loop and I'm not certain how to code it.

I am not supposed to use x ^ y and I have to use multiplication in a loop to
do this.

Here's what I have...

If rdoExp.Checked = True Then

If num2 = 0 Then

lblResult2.Text = "Cannot Raise to the power of Zero!"

Else

Dim x As Integer

Dim old_ans As Double

' Loop the Multiplication x Times

If Val(txtNum2.Text) = 2 Then

lblResult2.Text = Str(num1) + " ^" + Str(num2) + " =" + Str(num1 *
num1)

Else

For x = 1 To num2

result = (result * num2) + old_ans

Next

'Dump The Result into the Result Area of the Form

lblResult2.Text = Str(num1) + " ^" + Str(num2) + " =" + Str(result)

End If

'Reset result amount

result = 0

old_ans = 0

End If
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.576 / Virus Database: 365 - Release Date: 1/30/2004
Jul 17 '05 #1
9 6010
"VBNoob" <kingmeleeR.E.M.O.V.E.@nf.sympatico.ca> wrote
Got a problem in my loop and I'm not certain how to code it.


Step through the code, one command at a time, and verifiy that
the variables you are using have the values you expect.

LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2

"VBNoob" <kingmeleeR.E.M.O.V.E.@nf.sympatico.ca> wrote in message
news:bX*********************@ursa-nb00s0.nbnet.nb.ca...
lblResult2.Text = "Cannot Raise to the power of Zero!"
In all of my math classes, X^0 = 1
' Loop the Multiplication x Times
Think a minute: how many times do you multiply if Y = 2?
result = (result * num2) + old_ans


I have no idea where addition could play a role in exponents.
------

I think you need to lay out the math first:
if y =0, result = 1
if y = 1, result = x
if y > 1, then....

and also
if y = -1, result = 1/x
if y < -1, then....
Jul 17 '05 #3
On Sun, 1 Feb 2004 10:54:17 -0800, "Steve Gerrard"
<no*************@comcast.net> wrote:
<snip>

I think you need to lay out the math first:
if y =0, result = 1
if y = 1, result = x
if y > 1, then....


Select Case springs to mind ...
Jul 17 '05 #4
> > lblResult2.Text = "Cannot Raise to the power of Zero!"

In all of my math classes, X^0 = 1


For the most part, that is true... but not always...

http://www.faqs.org/faqs/sci-math-fa...lnumbers/0to0/

The problem comes up because X^0=1 and 0^X=0 for all non-zero X. However, at
when X does equal zero, these two equations lead one to contradictory
answers. VB considers 0^0 to be 1, my Casio calculator gives a Math Error.
You have to know the context you are using 0^0 in to be sure 1 is a
"correct" answer.

Rick - MVP


Jul 17 '05 #5
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:j8********************@comcast.com...
lblResult2.Text = "Cannot Raise to the power of Zero!"


In all of my math classes, X^0 = 1


For the most part, that is true... but not always...


I coded this function with a For Next loop. You would probably get errors
(or, as you said, as '1' as the answer for 0 and 0) but it does not use the
caret for exponentation. I am sure that you can come up with the answer for
this. Just think that the first time through any loop is going to use the
value twice, so you have to make sure the loop compensates for that.
Example: if your y value is 4, then the loop only needs to go through three
times since the first time will multiply x*x. Also, there shouldn't be any
addition, only multiplication. You also would need a check in place for
your '0' values to ensure they get handled properly since the for next loop
will choke if you pass it a lower value than the starting value. :)

If you absolutely cannot get this, email me (remove the nospam) and I will
try to explain in more detail for you what I am talking about, ok? :)

Ken
un*****@hotmail.nospam.com
Jul 17 '05 #6
Are you asking for a function that does powers without using the caret
symbol? If so,

Function Power(Base As Long, Exponent As Long) As Long
Dim Index As Long
Power = 1
For Index = 1 To Exponent
Power = Power * Base
Next
End Function

This returns 1 as the answer for 0 to the 0 power.

Rick - MVP
"Trousle Undrhil" <un*****@hotmail.nospam.com> wrote in message
news:Yh******************@bignews1.bellsouth.net.. .
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:j8********************@comcast.com...
> lblResult2.Text = "Cannot Raise to the power of Zero!"

In all of my math classes, X^0 = 1
For the most part, that is true... but not always...


I coded this function with a For Next loop. You would probably get errors
(or, as you said, as '1' as the answer for 0 and 0) but it does not use

the caret for exponentation. I am sure that you can come up with the answer for this. Just think that the first time through any loop is going to use the
value twice, so you have to make sure the loop compensates for that.
Example: if your y value is 4, then the loop only needs to go through three times since the first time will multiply x*x. Also, there shouldn't be any addition, only multiplication. You also would need a check in place for
your '0' values to ensure they get handled properly since the for next loop will choke if you pass it a lower value than the starting value. :)

If you absolutely cannot get this, email me (remove the nospam) and I will
try to explain in more detail for you what I am talking about, ok? :)

Ken
un*****@hotmail.nospam.com

Jul 17 '05 #7

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:A4********************@comcast.com...
This returns 1 as the answer for 0 to the 0 power.

Rick - MVP


Looking at your function I would say it returns a zero rather than 1 (since
0 * base = 0)

Also, it won't work for power of 0.5
Jul 17 '05 #8

"Raoul Watson" <Wa*****@IntelligenCIA.com> wrote in message
news:6A*****************@nwrdny02.gnilink.net...

"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:A4********************@comcast.com...
This returns 1 as the answer for 0 to the 0 power.

Rick - MVP

Looking at your function I would say it returns a zero rather than 1

(since 0 * base = 0)

Also, it won't work for power of 0.5


Oh.. cool.. I didn't see power preset to 1.
Jul 17 '05 #9
> > > This returns 1 as the answer for 0 to the 0 power.

Rick - MVP

Looking at your function I would say it returns a zero rather than 1

(since
0 * base = 0)

Also, it won't work for power of 0.5


True, I meant to post that it was only for integer powers. I declared Base
as Long, but that doesn't seem to be a necessary restriction... it looks
like Base could have been declared as Double also.

Oh.. cool.. I didn't see power preset to 1.


<g>
Rick - MVP
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ryoga | last post by:
How can I print out the value of a large double in plain decimal form without the exponential notation? For example (quick code): PlainPrint.java: --------------- public class PlainPrint {...
4
by: Timothy Fitz | last post by:
Why are all numberical literals in exponential notation floats? To me it is counter-intuitive for 1e3 to behave so fundamentally different from 1000. Timothy Fitz
1
by: Mahesha | last post by:
Exponential Moving avg is calculated using the formula. EMA = (Today's Price)* K + (EMA yesterday) * (1-K) where K = 2 / (N+1) The user is going to Input the K. It is something like F(N) =...
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
2
by: Rod Brick | last post by:
I'm trying to print a Double in straight decimal form, not exponential. I can't seem to accomplish this. This seems like it should be simple enough. The output I'm looking for is "0.00001", not...
8
by: Martin Jørgensen | last post by:
Hi, I have a program that reads in a couple of numbers from files and then stores them with some latex-code but I'm not satisfied with the exponential output, as it takes up too many character...
2
by: Poz | last post by:
Is there a way to convert an exponential number (held in string format) to non-exponential format without losing any precision in the number? For example, I have a string variable containing...
4
by: b4ukiran | last post by:
Hi all, I have a requirement to print large double values without the exponential notaion. The double value can be a declared variable or any calculated value within the code. In any case, I...
3
ashsa
by: ashsa | last post by:
Hi everyone, I am trying to display a numeric value fetched from an sql server table which is stored in the exponential notation. For eg, 0.08 is getting stored in the table as...
1
by: pankajprakash | last post by:
Hi, I have a decimal number. I need to convert this decimal value to exponential value. I have a vb.net code to convert from decimal to exponential value is Format(100000, #.0#E-##) . When I run this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.