This windows application finds the amount of your pay if your pay is doubled each day, starting with a penny a day or a nickel a day. Instead of one month's salary, a boss offers her new employees a penny the first day and experienced employees a nickel the first day under a new pay system. Each day the pay will double.
Restriction: The minimum number of days for the pay period is 19 days for the new employees and 16 days for the experienced. The maximum number of days in a pay period is 22 days.
I have everything working except the double your pay each day part.This is what I have so far......

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim intNumberOfDays As Integer
Const decPenny As Decimal = 0.01D
Const decNickel As Decimal = 0.05D
Dim decAmountDisplay As Decimal
Dim decChosenPay As Decimal
Const decDouble As Decimal = 2D
Dim decTotalOfDayPay As Decimal

'This code validates the user input as numeric and a positive number.

If IsNumeric(Me.txtNumberOfDays.Text) Then
intNumberOfDays = Convert.ToInt32(Me.txtNumberOfDays.Text)
If intNumberOfDays > 0 Then

'This code will extract what the user has chosen as their first day pay rate.

If radPenny.Checked = True Then
decChosenPay = decPenny
ElseIf radNickel.Checked = True Then
decChosenPay = decNickel
End If
'This code will double the pay rate each day after the first day
If intNumberOfDays > 1 Then
decChosenPay += decTotalOfDayPay
decAmountDisplay = decChosenPay * decDouble

decAmountDisplay = intNumberOfDays * decChosenPay
Me.lblAmountDisplay.Text = decAmountDisplay.ToString("C")
Me.lblAmountDisplay.Visible = True
MessageBox.Show("You entered a negative value, please enter a number greater than zero!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End If


'Display MessageBox if negative or nonnumeric value is entered
MessageBox.Show("You entered an invalid value, please try again!", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Me.radNickel.Checked = False
Me.radPenny.Checked = True
Me.lblAmountDisplay.Visible = False
Me.btnCalculate.Enabled = True

End If

End If

I don't know how to use loops to "double your pay" :(

Edited by ndshah: n/a

7 Years
Discussion Span
Last Post by TomW

If you use a NumericUpDown control it will save you some datatype conversions and validation and will limit users to only entering numeric values. For the calculation I would use a loop; passing the days worked and starting amount.

decPay = decStartingAmount

For intDay = 2 To intTotalDaysWorked
    decPay *= 2
Next intDay

Edited by TomW: n/a


Here is an example written in a console app showing the calculated salary for each day of the pay period. The final result is all that is needed in your app but its good to at least follow along what is happening with each itteration of the loop.

Module Module1
    Sub Main()

        Console.WriteLine("Total Salary: {0}", GetSalary(0.01D, 19).ToString("c"))

    End Sub

    Private Function GetSalary(ByVal decStartingAmount As Decimal, ByVal intTotalDaysWorked As Integer) As Decimal

        Dim decSalary As Decimal = 0

        For intDay As Integer = 1 To intTotalDaysWorked

            If intDay = 1 Then
                decSalary = decStartingAmount
                decSalary *= 2
            End If

            Console.WriteLine("Day #{0:00}){1}Salary: {2}" _
                              , intDay _
                              , ControlChars.Tab _
                              , decSalary.ToString("c"))
        Next intDay

        Return decSalary

    End Function
End Module

Edited by TomW: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.