these person is hired by her employee which it agree that the salary would be one penny the first day, two pennies the second day and four pennies the third day and continuing to double each day. i have to use a combo box to select the days that the empoyee will be working and calculate the total amount of pay that will received.

its not calculating right?
Dim intDay As Integer = 0
Dim intCount As Integer = 1
Dim decPay As Decimal = 0
Dim intNumDays As Integer
Dim dblTotal As Double = 0
Dim dblTotalPay As Double
Dim dblPay As Double
Dim decTotal As Decimal
Dim intCurrent As Integer

If Integer.TryParse(cboDay.Text, intNumDays) Then

For intCount = 1 To intNumDays
intDay += 1


If intNumDays > 0 Then
intCurrent = CInt((intDay ^ 2.0))
decTotal = decTotal + intCurrent
lblPay.Text = decTotal.ToString ("C")
End If
End If

Start by writing out what you want to do step by step (this is called pseudo-code). You should do this before you write any code. Then try to step through your pseudo-code using pencil and paper (for a simple case such as 5 days) to see if your "code" does what you want. Then you can replace it with actual code.

Your problem boils down to finding the total pay after a given number of days for a person who earns one penny the first day and whose salary doubles each successive day. Clearly you need several "places" or variables to keep track of the numbers. Because there are no fractions to keep track of, everything can be integer. You need to keep track of the number of days, the salary on any given day and the total salary.

You get the number of days from the combo box. Your loop executes once for each day worked so you have that right, however, intDay is useless because it ends up just being equal to intNumDays.

Incidentally, you prefix all your variables with strings indicating the variable type. This is called Hungarian notation and has fallen out of favour. I suggest more descriptive variable names such as

totalSalary, todaySalary, numDays

and for simple loops like in this example, "i", or "day" is sufficient for a loop index. Just a suggestion, however.

Back to the pseudo-code. It boils down to

for each day worked
    calculate the salary for today
    add that to the total salary
display the number of days worked and the total salary paid

I think you'll find that attacking the problem this way and then translating to actual code will make the process easier to understand. Also, you can turn your pseudo-code into comments to make your code clearer. This is more important as your code gets more complex and it is a good habit to develop early.

PS - Please add code tags around posted code to preserve formatting.

This article has been dead for over six months. Start a new discussion instead.