Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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
0
neomage23
Asked:
neomage23
  • 2
2 Solutions
 
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
 
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

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now