Solved

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

Posted on 2004-11-09
194 Views
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
' 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
Question by:neomage23

LVL 53

Accepted Solution

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
' 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

LVL 14

Assisted Solution

Hi

>>TotalSalary = OneDaysPay * 2
Change it to

TotalSalary = TotalSalary + OneDaysPay * 2

;-)
Shiju

0

LVL 6

Author Comment

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

LVL 6

Author Comment

No problem ai.
0

Featured Post

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…