PDA

View Full Version : Solved: Double a value multiple times



austenr
03-24-2010, 11:36 AM
Is there an easy way to do this:

Say you start with a penny and you double it each day for 30 days.

Day 1 you have a penny.
Day 2 you have 2 cents
Day 3 you have 4 cents
etc.

Thought of using a Do Until loop but there must be an easier way. Suggestions?

mdmackillop
03-24-2010, 11:49 AM
=2^29 or =2^(A1-1)

austenr
03-24-2010, 11:55 AM
What about a value entered into a text box?

mdmackillop
03-24-2010, 12:07 PM
Sub Test()
MsgBox 2 ^ (InputBox("Double for how many days?") - 1)
End Sub

SamT
03-24-2010, 12:20 PM
=x(2^29) for values of x greater than 1

austenr
03-24-2010, 02:43 PM
Trying this but it doesn't work. radPenny and radNickel are radio buttons:


Private Sub btnCalculatePay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculatePay.Click
Dim decDaysInPayPeriod As Decimal
Dim decGrossPay As Decimal
If txtDaysInPayPeriod.Text = vbNullString Then
MsgBox("You must enter a value in Days in Pay Period")
End If
If IsNumeric(txtDaysInPayPeriod.Text) Then
decDaysInPayPeriod = Convert.ToDecimal(txtDaysInPayPeriod.Text)
End If
'determine gross pay
If radPenny.Checked = True Then
decGrossPay = (1 ^ decDaysInPayPeriod) / 100
Else
decGrossPay = (5 ^ decDaysInPayPeriod) / 100
End If
txtPay.Text = decGrossPay.ToString("C")
End Sub

mdmackillop
03-24-2010, 03:37 PM
Hi Austen,
I guess this is VB as it won't compile for me. I have doubts regarding your use of the exponentials.
(1 ^ decDaysInPayPeriod) / 100 will always equal 0.01