A program using loops that outputs each step to a label...

Hello experts...!

I'm new to programming and stuck on something...using VB.net and loops how would you make a program that can calculate how much money one would have at the end of 30 days if they got paid one penny on the first day, and double each subsequent day...day two .02, day 3 .04 etc...?

And how do you make it print each step that it does on a single line...like a line for day one, a line for day two, etc, that says DAY, TOTAL PAID, and TOTAL SALARY FOR THE MONTH SO FAR?


This is what I have so far...

Private Sub btnCalculate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnCalculate.Click
            ' calculate and display the salary for each day and the total for each day
            Dim TotalSalary As Single
        Dim OneDaysPay As Single
        Dim DayCount As Integer
            ' display headings in output label
        lblOutput.Text = "Day      Pay       Total" & vbNewLine
            ' Initialize total
        TotalSalary = 0.01
            ' start with 1 cent on the first day
            OneDaysPay = 0.01 ' start with one cent the first day
            ' Write a loop that proceeds for 30 days, displaying the day's
            ' pay and the total so far, then doubling the day's pay
        ' After the loop, tell programmer which pay rate to take
        DayCount = 1
        For DayCount = 1 To 30
            TotalSalary = OneDaysPay * 2
        Next DayCount
        Me.lblOutput.Text = TotalSalary


    End Sub


Thanks!

-neo
LVL 6
neomage23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DhaestCommented:
   Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        ' calculate and display the salary for each day and the total for each day
        Dim TotalSalary As Single
        Dim OneDaysPay As Single
        Dim DayCount As Integer
        ' display headings in output label
        lblOutput.Text = "Day" & vbTab & "Pay" & vbTab & "Total" & vbNewLine
        ' Initialize total
        TotalSalary = 0.01
        ' start with 1 cent on the first day
        OneDaysPay = 0.01 ' start with one cent the first day
        ' Write a loop that proceeds for 30 days, displaying the day's
        ' pay and the total so far, then doubling the day's pay
        ' After the loop, tell programmer which pay rate to take
        DayCount = 1
        For DayCount = 1 To 30
            lblOutput.Text = lblOutput.Text & DayCount & vbTab & OneDaysPay & vbTab & TotalSalary & vbNewLine
            OneDaysPay = OneDaysPay * 2
            TotalSalary = TotalSalary + OneDaysPay
        Next DayCount
    End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Shiju SasidharanAssoc Project ManagerCommented:
Hi

>>TotalSalary = OneDaysPay * 2
Change it to

           TotalSalary = TotalSalary + OneDaysPay * 2

;-)
Shiju

               
0
neomage23Author Commented:
Thanks DHaest...for the code...and thanks shijusn for the correction.

ee ai construct: Good eye! This is actually a challenge question FROM a schoolbook, but I don't go to school. I have the book and I'm trying to learn that's all. As you can see I was on the right track, just not thinking in complete terms. It's hard for me to visualize something like "onedayspay = onedayspay * 2", but now I get it.

Thanks again!


-neomage
0
neomage23Author Commented:
No problem ai.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.