Ok folks. You'll helped me out before and I am hoping you can help me out again.
We have to write a program that compares between making $100 per day for 10 days or making $1 per day the first day and then doubling it each day for 10 days.
Here is what I have so far.
Private Sub compareButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles compareButton.Click
' Calculates how much money you make if you start with $1 and double each day
'initialize variable
Dim totalPay As Double = 1
Dim sum As Double = 0
For doublePerDay As Double = 1 To 10 Step 1
sum = totalPay
totalPay = sum * 2
Next doublePerDay
doubleMoneyTextBox.Text = totalPay.ToString("C2")
'Calculates how much you make for 10 days if you make $10 per day
Dim dailyPay As Double = 100
For dailyPerDay As Double = 1 To 9 Step 1
dailyPay += 100
Next dailyPerDay
dailyPayTextBox.Text = dailyPay.ToString("C2")
End Sub
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
End Class
For the doubling per day, I am getting a total of 1024 but it is supposed to be 1023 and short of subtracting 1 from the final total, I was wondering what I am doing wrong. Here is the email that she sent us to help but I just can't figure it out.
Quite a few of you had trouble with this one, so here is a hint for those of you who would like to take another try at it:
Happy Temps - Option 1 should add up to 1023. You start out with a dollar and the amount doubles each day so it should be a sum that looks like this: 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 +512
Option 1 needs to be a sum therefore you need to add up the pay for each day. An easy way to do this is set up the "pay" for each day as a different calculation and then use your option one variable just to add up the amount for each day in the loop. Of course you will need to update the pay each time through the loop.
So the pay should be initialized to one dollar and option one (since it is just a sum) should be initialized to zero. Then, in your for loop update the sum then update the pay.
We have to write a program that compares between making $100 per day for 10 days or making $1 per day the first day and then doubling it each day for 10 days.
Here is what I have so far.
Private Sub compareButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles compareButton.Click
' Calculates how much money you make if you start with $1 and double each day
'initialize variable
Dim totalPay As Double = 1
Dim sum As Double = 0
For doublePerDay As Double = 1 To 10 Step 1
sum = totalPay
totalPay = sum * 2
Next doublePerDay
doubleMoneyTextBox.Text = totalPay.ToString("C2")
'Calculates how much you make for 10 days if you make $10 per day
Dim dailyPay As Double = 100
For dailyPerDay As Double = 1 To 9 Step 1
dailyPay += 100
Next dailyPerDay
dailyPayTextBox.Text = dailyPay.ToString("C2")
End Sub
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
End Class
For the doubling per day, I am getting a total of 1024 but it is supposed to be 1023 and short of subtracting 1 from the final total, I was wondering what I am doing wrong. Here is the email that she sent us to help but I just can't figure it out.
Quite a few of you had trouble with this one, so here is a hint for those of you who would like to take another try at it:
Happy Temps - Option 1 should add up to 1023. You start out with a dollar and the amount doubles each day so it should be a sum that looks like this: 1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 +512
Option 1 needs to be a sum therefore you need to add up the pay for each day. An easy way to do this is set up the "pay" for each day as a different calculation and then use your option one variable just to add up the amount for each day in the loop. Of course you will need to update the pay each time through the loop.
So the pay should be initialized to one dollar and option one (since it is just a sum) should be initialized to zero. Then, in your for loop update the sum then update the pay.