My program to display employee records works fine other than the face that it displays incorrect values when it comes to pay. What needs to be changed?
Sub AddPlist(month As String, age As String, employeenumberid As Integer, hourlyrateline As Integer)
Dim hoursworkedline As String
Dim normalhoursworked As Integer
Dim overtimerate As String
Dim normalpay As Decimal
Dim overtimepay As Decimal
Dim overtimehoursworked As Integer
Dim grosspay As Decimal
Dim taxrate As Decimal
Dim taxdeducted As Decimal
Dim nideducted As Decimal
Dim netpay As Decimal
Do
Console.Write("Please enter hoursworked: ")
hoursworkedline = Console.ReadLine()
If Not hoursworkedline IsNot Nothing OrElse Not IsNumeric(hoursworkedline) Then Console.Write("hoursworked must be entered!!: ")
Loop While Not hoursworkedline IsNot Nothing OrElse Not IsNumeric(hoursworkedline)
If hoursworkedline > 40 Then
normalhoursworked = 40
overtimerate = hourlyrateline * 0.15
overtimehoursworked = hoursworkedline - 40
normalpay = normalhoursworked * hourlyrateline
overtimepay = overtimehoursworked * overtimerate
grosspay = normalpay + overtimepay
taxrate = If(age < 18, 18, If(age < 60, 25, If(age > 60, 20, Nothing)))
taxdeducted = grosspay * taxrate
nideducted = grosspay * ((grosspay / 100) * 7)
netpay = grosspay - taxdeducted - nideducted
Else
normalhoursworked = hoursworkedline
overtimerate = hourlyrateline * 0.15
overtimehoursworked = 0
normalpay = normalhoursworked * hourlyrateline
overtimepay = 0
grosspay = normalpay + overtimepay
taxrate = If(age < 18, 18, If(age < 60, 25, If(age > 60, 20, Nothing)))
taxdeducted = grosspay * taxrate
nideducted = grosspay * ((grosspay / 100) * 7)
netpay = grosspay - taxdeducted - nideducted
End If
One thing I noticed wrong is you're only paying 15% of the hourly rate for overtime. I think you mean to multiply by 1.5 not .15
Plus you have a lot of duplication in your code consider this:
If hoursworkedline > 40 Then
normalhoursworked = 40
overtimehoursworked = hoursworkedline - 40
Else
normalhoursworked = hoursworkedline
overtimehoursworked = 0
End If
overtimerate = hourlyrateline * 1.5
normalpay = normalhoursworked * hourlyrateline
overtimepay = overtimehoursworked * overtimerate
grosspay = normalpay + overtimepay
'Also your taxrate algorithm doesn't allow for someone exactly 60
taxrate = If(age < 18, 18, If(age < 60, 25, If(age >= 60, 20, Nothing)))
'Another thing your multiplying the grosspay by whole numbers not percentages
taxdeducted = grosspay * (taxrate / 100)
'Not sure what outcome you expect from this but it doesn't look quite right
nideducted = grosspay * ((grosspay / 100) * 7)
netpay = grosspay - taxdeducted - nideducted
Related
If I have more (or less) data in my Access 2010 graph, I want to decrease (or increase) the number of tick marks on the X-axis. I looked for the right syntax but I couldn't find it.
I did the same for the Y-axis Title and that works fine:
me.Graph1.Object.Axes(2,1).AxisTitles.Caption="g/ml"
For number of tick-marks of the X-axis; I've tried a number of words can not find the right one. It stopped at:
me.Graph.Object.Axes(1,1).Scale.???????? (I want a number of categories = 3 )
Example code from my db for XYScatter chart. xlCategory is for X-axis and xlValue is Y-axis.
this procedure is in a standard module and called by a form and a report
Sub FormatProcGraph(strObject As String, strLabNum As String, booMetric As Boolean, dblOMC, dblMDD)
'format Proctor graph on form and report
Dim obj As Object
Dim gc As Object
Dim intMaxD As Integer
Dim intMinD As Integer
Dim intM As Integer
If strObject Like "Lab*" Then
Set obj = Reports(strObject)
Else
Set obj = Forms(strObject).Controls("ctrProctor").Form
End If
Set gc = obj("gphDensity")
intMaxD = Nz(Int(dblMDD), 0)
intMinD = Nz(Int(DMin("D", "GraphProctor", "Source='Lab' AND LabNum='" & strLabNum & "'")), 0)
With gc
'format y axis scale
If booMetric = True Then
intMaxD = intMaxD + IIf(intMaxD - intMinD < 125, 50, IIf(intMaxD - intMinD < 250, 25, 0))
.Axes(xlValue).MaximumScale = intMaxD
.Axes(xlValue).MinimumScale = intMaxD - 250
.Axes(xlValue).MajorUnit = 50
.Axes(xlValue).MinorUnit = 10
Else
intMaxD = intMaxD + IIf(intMaxD - intMinD < 6, 2, IIf(intMaxD - intMinD < 10, 1, 0))
.Axes(xlValue).MaximumScale = intMaxD
.Axes(xlValue).MinimumScale = intMaxD - 10
.Axes(xlValue).MajorUnit = 2
.Axes(xlValue).MinorUnit = 0.4
End If
'format x axis scale
If Int(dblOMC) > 6 Then
intM = Int(dblOMC) + IIf(dblOMC - Int(dblOMC) >= 0.5, 1, 0)
.Axes(xlCategory).MaximumScale = intM + 7
.Axes(xlCategory).MinimumScale = intM - 5
End If
'y axis label
.Axes(xlValue, xlPrimary).HasTitle = True
If booMetric = True Then
.Axes(xlValue, xlPrimary).AxisTitle.Text = "Dry Density, kg/cu.m"
End If
End With
End Sub
this procedure is behind report
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'format graphs
Dim MinUWT As Double, MaxUWT As Double
Dim MinDry As Double, MaxDry As Double
Dim MinSoak As Double, MaxSoak As Double
Dim MinRat As Double, MaxRat As Double
With Me
If Not IsNull(!MinOfA) Then
MinUWT = Int(!MinOfU) - IIf(!MaxOfU - !MinOfU <= 2, 3, 1)
MaxUWT = MinUWT + 8
MinDry = Int(!MinOfD / 5) * 5 - (40 - Int((Int(!MaxOfD / 5) * 5 + 5 - Int(!MinOfD / 5) * 5) / 10) * 10) / 2
MaxDry = MinDry + 40
MinSoak = Int(!MinOfS / 5) * 5 - (40 - Int((Int(!MaxOfS / 5) * 5 + 5 - Int(!MinOfS / 5) * 5) / 10) * 10) / 2
MaxSoak = MinSoak + 40
MinRat = Int(!MinOfR / 5) * 5 - (40 - Int((Int(!MaxOfR / 5) * 5 + 5 - Int(!MinOfR / 5) * 5) / 10) * 10) / 2
MaxRat = MinRat + 40
.gphWeight.Axes(xlValue).MinimumScale = MinUWT
.gphWeight.Axes(xlValue).MaximumScale = MaxUWT
.gphITSdry.Axes(xlValue).MinimumScale = MinDry
.gphITSdry.Axes(xlValue).MaximumScale = MaxDry
.gphITSsoak.Axes(xlValue).MinimumScale = MinSoak
.gphITSsoak.Axes(xlValue).MaximumScale = MaxSoak
.gphITSret.Axes(xlValue).MinimumScale = MinRat
.gphITSret.Axes(xlValue).MaximumScale = MaxRat
If Me!Metric = True Then
.gphWeight.Axes(xlValue, xlPrimary).AxisTitle.Text = "Unit Weight, kg/cu.cm"
.gphGradation.Axes(xlCategory, xlPrimary).AxisTitle.Text = "Sieve Size (mm)"
.gphITSdry.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Dry, kg/cu.cm"
.gphITSsoak.Axes(xlValue, xlPrimary).AxisTitle.Text = "ITS Soaked, kg/cu.cm"
End If
End If
End With
End Sub
Imagine a range of numbers from -133 to +71.
I want to find the first and last numbers in the range that divide by 20: in this case it would be -120 and +60.
I can write a For loop that tests each value and stores the required values:
Dim resultFirst, resultLast As Integer
Dim FirstFound As Boolean = False
For a As Integer = -133 To 71
If a Mod 20 = 0 Then
If FirstFound = False Then
resultFirst = a
FirstFound = True
End If
resultLast = a
End If
Next
but I suspect there is a simpler formula.
You can use Enumerable.Range() and the LINQ-methods Where, Min and Max
Dim resultFirst As Integer
Dim resultLast As Integer
Dim min As Integer = -133
Dim max As Integer = 71
Dim div As Integer = 20
resultFirst = Enumerable.Range(min, max - min + 1).Where(Function(x) x Mod div = 0).Min()
resultLast = Enumerable.Range(min, max - min + 1).Where(Function(x) x Mod div = 0).Max()
Try this one
Dim s As IEnumerable(Of Integer) =
Enumerable.Range(-133, 133 + 72)
Dim minV As Integer = s.AsEnumerable().Where(Function(n) n Mod 20 = 0).Min(Function(n) n)
Dim maxV As Integer = s.AsEnumerable().Where(Function(n) n Mod 20 = 0).Max(Function(n) n)
Console.WriteLine(minV.ToString() & " " & maxV.ToString())
Console.ReadLine()
You can use the following to get the first and last value which is dividable by 20:
Dim fromValue As Integer = -133
Dim first As Integer = (fromValue - (fromValue Mod 20)) + IIf(fromValue > 0 And fromValue Mod 20 <> 0, 20, 0)
Dim toValue As Integer = 71
Dim last As Integer = (toValue - (toValue Mod 20)) - IIf(toValue < 0 And toValue Mod 20 <> 0, 20, 0)
You can also create a function using the above formula:
Private Function GetResult(ByVal fromInt As Integer, ByVal toInt As Integer, ByVal divider As Integer) As Integer()
'set the real from and to value from parameter.
Dim fromValue As Integer = Math.Min(fromInt, toInt)
Dim toValue As Integer = Math.Max(fromInt, toInt)
'get the first and last number dividable by divider between numbers.
Dim first As Integer = (fromValue - (fromValue Mod divider)) + IIf(fromValue > 0 And fromValue Mod divider <> 0, divider, 0)
Dim last As Integer = (toValue - (toValue Mod divider)) - IIf(toValue < 0 And toValue Mod divider <> 0, divider, 0)
If first > toValue Or last < fromValue Then
Return {}
Else
Return {first, last}
End If
End Function
Some test cases for the above function:
GetResult(-133, 71, 20) '0: -120; 1: 60
GetResult(71, -133, 20) '0: -120; 1: 60
GetResult(100, 119, 20) '0: 100; 1: 100
GetResult(-113, -112, 20) 'empty array
GetResult(120, 140, 20) '0: 120; 1: 140
Im trying to get the discounted price using select case but i keep getting the regular price
I select student and click on yoga and personal trainer option then i put 11 months according to the calculation its supppose to be 76.50 monthly fee , total 841.50 but i get 85 monthly and total 935 . Help Thank you
Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decMontlyFee As Decimal
Dim decTotalFee As Decimal
Dim discount As Double
Dim intMonths As Integer
Dim decAdultFee As Decimal = 40
Dim decChildFee As Decimal = 20
Dim decStudentFee As Decimal = 25
Dim decSeniorFee As Decimal = 30
Dim decYogaFee As Decimal = 10
Dim decKarateFee As Decimal = 30
Dim decTrainerFee As Decimal = 50
If radAdult.Checked = True Then
decMontlyFee = decAdultFee
ElseIf radChild.Checked = True Then
decMontlyFee = decChildFee
ElseIf radStudent.Checked = True Then
decMontlyFee = decStudentFee
ElseIf radSenior.Checked = True Then
decMontlyFee = decSeniorFee
End If
If chkYoga.Checked = True Then
decMontlyFee += decYogaFee
End If
If chkTrainer.Checked = True Then
decMontlyFee += decTrainerFee
End If
If chkKarate.Checked = True Then
decMontlyFee += decKarateFee
End If
Select Case intMonths
Case Is <= 3
discount = 0
Case 4 To 6
discount = decMontlyFee * 0.05
Case 7 To 9
discount = decMontlyFee * 0.08
Case Is >= 10
discount = decMontlyFee * 0.1
End Select
decMontlyFee -= discount
decTotalFee = decMontlyFee * txtMonths.Text
lblMonthlyFee.Text = decMontlyFee.ToString("c")
lblTotalFee.Text = decTotalFee.ToString("c")
End Sub
End Class
You will need to read the value for intMonths because it is only declared and not assigned.
Assign your intMonths to the TextBox value. Simplify your syntax.
Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decMontlyFee As Decimal
Dim decTotalFee As Decimal
Dim intMonths As Integer = Integer.Parse(txtMonths.Text)
Dim decAdultFee As Decimal = 40
Dim decChildFee As Decimal = 20
Dim decStudentFee As Decimal = 25
Dim decSeniorFee As Decimal = 30
Dim decYogaFee As Decimal = 10
Dim decKarateFee As Decimal = 30
Dim decTrainerFee As Decimal = 50
decMontlyFee = If(radAdult.Checked, decAdultFee, decMontlyFee)
decMontlyFee = If(radChild.Checked, decChildFee, decMontlyFee)
decMontlyFee = If(radStudent.Checked, decStudentFee, decMontlyFee)
decMontlyFee = If(radSenior.Checked, decSeniorFee, decMontlyFee)
decMontlyFee += If(chkYoga.Checked, decYogaFee, 0)
decMontlyFee += If(chkTrainer.Checked, decTrainerFee, 0)
decMontlyFee += If(chkKarate.Checked, decKarateFee, 0)
Select Case intMonths
Case Is <= 3
decMontlyFee *= 1
Case 4 To 6
decMontlyFee *= 0.95
Case 7 To 9
decMontlyFee *= 0.92
Case Is >= 10
decMontlyFee *= 0.9
End Select
decTotalFee = decMontlyFee * intMonths
lblMonthlyFee.Text = decMontlyFee.ToString("c")
lblTotalFee.Text = decTotalFee.ToString("c")
End Sub
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Form 2 is to enter ladder base and its off set value and for snakes where the snake head is and skakes off set value.
Not able to figure out why its not working . When the values are entered to show simulation it show's up error sandl is private and the other one is the validation one .
Public Class Form2
Dim sandl(99) As Integer
Dim snakeshead As TextBox()
Dim snakesoffset As TextBox()
Dim ladderfoot As TextBox()
Dim ladderoffset As TextBox()
Dim rnd As Random = New Random
Sub initialise()
For i = 0 To 99
sandl(i) = 0 ' reset data
Next
End Sub
Sub snake()
snakeshead = {txthead1, txthead2, txthead3, txthead4, txthead5, txthead6, txthead7, txthead8, txthead9, txthead10}
snakesoffset = {txtoffset1, txtoffset2, txtoffset3, txtoffset4, txtoffset5, txtoffset6, txtoffset7, txtoffset8, txtoffset9, txtoffset10}
' SnakeHead(i).Text = (i + 81).ToString
' SnakeOffset(i).Text = "10" '(i + 10).ToString
For i As Integer = 0 To 9
While True
Dim base = rnd.Next(90) + 11
If sandl(base - 1) <> 0 Then
Continue While
End If
Dim offset = rnd.Next(20) + 10
If base - offset < 1 Then
Continue While
End If
snakeshead(i).Text = base.ToString
snakesoffset(i).Text = offset.ToString
sandl(base - 1) = -offset
Exit While
End While
Next
End Sub
Sub ladders()
ladderfoot = {txtladder1, txtladder2, txtladder3, txtladder4, txtladder5, txtladder6, txtladder7, txtladder8, txtladder9, txtladder10}
ladderoffset = {txtladderoffset1, txtladderoffset2, txtladderoffset3, txtladderoffset4, txtladderoffset5, txtladderoffset6, txtladderoffset7, txtladderoffset8, txtladderoffset9, txtladderoffset10}
'For i As Integer = 0 To 9
' LadderFoot(i).Text = (i + 11).ToString
' LadderOffset(i).Text = "10"
For i As Integer = 0 To 99
sandl(i) = 0 'reset data
Next
For i As Integer = 0 To 9
While True
Dim base = rnd.Next(90) + 1
If sandl(base - 1) <> 0 Then
Continue While
End If
Dim offset = rnd.Next(20) + 10
If base + offset > 100 Then
Continue While
End If
ladderfoot(i).Text = base.ToString
ladderoffset(i).Text = offset.ToString
sandl(base - 1) = offset
Exit While
End While
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
For i As Integer = 0 To 99
sandl(i) = 0 'reset data
Next
Dim valid = Validate(ladderfoot, ladderoffset, +1, "Ladder")
If (valid) Then
valid = Validate(snakeshead, snakesoffset, -1, "Snake")
End If
If (valid) Then
'Form3 = New Form3
Form3.ShowDialog()
End If
End Sub
Private Function Validate(tbBase() As TextBox, tbOffset() As TextBox, delta As Integer, s As String) As Boolean
For i As Integer = 0 To 9
Dim base As Integer
If ((Not Integer.TryParse(tbBase(i).Text.Trim(), base)) OrElse (base < 1) OrElse (base > 100) OrElse (sandl(base - 1) <> 0)) Then
MessageBox.Show(s & (i + 1).ToString() & " base is invalid.")
tbBase(i).Select()
tbBase(i).SelectAll()
Return False
End If
base -= 1 'zero based
Dim offset As Integer
If ((Not Integer.TryParse(tbOffset(i).Text.Trim(), offset)) OrElse (offset < 10) OrElse (offset > 30) OrElse (base + offset * delta < 0) OrElse (base + offset * delta >= 100)) Then
MessageBox.Show(s & (i + 1).ToString() & " offset is invalid.")
tbOffset(i).Select()
tbOffset(i).SelectAll()
Return False
End If
sandl(base) = offset * delta 'write offset
Next
Return True
End Function
End Class
Public Class Form3
Enum EState
Dice
Move
Slide
Wait
Win
End Enum
Dim Fnt = New Font("Arial", 16)
Dim FntBig = New Font("Arial", 256)
Dim Frame As Integer = -1 'counter
Dim State = EState.Dice
Dim Rnd As Random = New Random
Dim Dice As Integer
Dim Pos As Point = New Point(32, 640 + 32)
Dim CurrentIndex As Integer = -1
Dim NextIndex As Integer
Dim TargetIndex As Integer
Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dice = 0
Frame = -1
State = EState.Dice
Pos = New Point(32, 640 + 32)
CurrentIndex = -1
End Sub
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
DrawBackground(e.Graphics)
Frame += 1
Dim oldState = State
Select Case State
Case EState.Dice
If Frame = 0 Then
Dice = Rnd.Next(6) + 1 'roll dice
TargetIndex = CurrentIndex + Dice
NextIndex = CurrentIndex
ElseIf Frame >= 63 Then
If CurrentIndex + Dice < 100 Then
State = EState.Move 'valid dice
Else
State = EState.Wait 'invalid dice
End If
Dice = 0
End If
Case EState.Move
If Frame Mod 64 = 0 Then
CurrentIndex = NextIndex
If CurrentIndex = TargetIndex Then
If CurrentIndex < 99 Then 'not win
If Form2.sandl(CurrentIndex) <> 0 Then
State = EState.Slide 'snake or ladder
Else
State = EState.Dice 'empty tile
End If
TargetIndex = CurrentIndex + Form2.sandl(CurrentIndex)
Else
State = EState.Win 'win
End If
Else
NextIndex = CurrentIndex + 1 'move
End If
Else
Dim c = GetCoordinate(CurrentIndex)
Dim n = GetCoordinate(NextIndex)
Dim dx = (n.X - c.X)
Dim dy = (n.Y - c.Y)
Pos.X = c.X * 64 + (dx * (Frame Mod 64)) + 32
Pos.Y = c.Y * 64 + (dy * (Frame Mod 64)) + 32
End If
Case EState.Slide
If Frame >= 63 Then
CurrentIndex = TargetIndex
If CurrentIndex < 99 Then
State = EState.Dice 'not win
Else
State = EState.Win 'win
End If
Else
Dim c = GetCoordinate(CurrentIndex)
Dim n = GetCoordinate(TargetIndex)
Dim dx = (n.X - c.X)
Dim dy = (n.Y - c.Y)
Pos.X = c.X * 64 + (dx * (Frame Mod 64)) + 32
Pos.Y = c.Y * 64 + (dy * (Frame Mod 64)) + 32
End If
Case EState.Wait
If Frame >= 63 Then
State = EState.Dice
End If
End Select
e.Graphics.FillEllipse(Brushes.Blue, Pos.X - 16, Pos.Y - 16, 32, 32) 'draw player
If Dice > 0 Then
Dim size = e.Graphics.MeasureString(Dice.ToString, FntBig)
e.Graphics.DrawString(Dice.ToString, FntBig, Brushes.Black, 320 - size.Width / 2, 320 - size.Height / 2) 'print dice
End If
If State <> oldState Then
Frame = -1 'reset counter
End If
If State <> EState.Win Then
PictureBox1.Invalidate() 'schedule next paint
End If
End Sub
Private Sub DrawBackground(g As Graphics)
For y As Integer = 0 To 9
For x As Integer = 0 To 9
If (((x + y) Mod 2) = 0) Then
g.FillRectangle(Brushes.LightGray, x * 64, y * 64, 64, 64) 'dark rectangle
End If
Dim z = (9 - y) * 10 + x + 1
If y Mod 2 = 0 Then
z = (9 - y) * 10 + (9 - x) + 1
End If
g.DrawString(z.ToString, Fnt, Brushes.Black, x * 64, y * 64) 'number
Next
Next
For i As Integer = 0 To 99
If Form2.sandl(i) <> 0 Then
Dim base = GetCoordinate(i)
Dim offset = GetCoordinate(i + Form2.sandl(i))
If Form2.sandl(i) > 0 Then 'ladder
Dim delta = Math.Abs(base.X - offset.X) + 4
g.DrawLine(Pens.Green, base.X * 64 + 32 - delta, base.Y * 64 + 32, offset.X * 64 + 32 - delta, offset.Y * 64 + 32) 'left part
g.DrawLine(Pens.Green, base.X * 64 + 32 + delta, base.Y * 64 + 32, offset.X * 64 + 32 + delta, offset.Y * 64 + 32) 'right part
Else 'snake
g.DrawLine(Pens.Red, base.X * 64 + 32, base.Y * 64 + 32, offset.X * 64 + 32, offset.Y * 64 + 32) 'red line
End If
End If
Next
End Sub
Private Function GetCoordinate(i As Integer) As Point
Dim result As Point
result.Y = 9 - (i \ 10)
result.X = i Mod 10
If result.Y Mod 2 = 0 Then
result.X = 9 - result.X
End If
Return result
End Function
End Class
In Form2, change your declaration from
Dim sandl(99) As Integer
to
Public sandl(99) As Integer
This would allow Form3 to access your integer array
Rename your Validate method to something else, like ValidateTextBoxes, or if you intend to overload the base.Validate, then declare as
Private Overloads Function Validate
I've got this program to calculate the cost of sheets of paper. First the prices and bundles are declared and intialized. Then I use if else statements with division and modulos to break down the bundle into charging rates. Although my paper bundle amounts are correctly computed, my total costs are off. Can anyone spot what I'm doing wrong here?
Module Paper
Sub Main()
'declare variables
Dim PaperAmountReq As Double
Dim PricePer_1_Sheet As Double = 0.1
Dim PricePer_100_Sheets As Double = 0.055
Dim PricePer_500_Sheets As Double = 0.04
Dim PricePer_1000_Sheets As Double = 0.03
Dim NumberOfSingles As Double = 0
Dim NumberOf100s As Double = 0
Dim NumberOf500s As Double = 0
Dim Numberof1000s As Double = 0
Dim TotalCost As Double
Console.Write("Enter number of sheets of paper needed: ")
PaperAmountReq = Console.Readline
If PaperAmountReq / 1000 >= 1 Then
Numberof1000s = PaperAmountReq \ 1000
PaperAmountReq = PaperAmountReq Mod 1000
End If
If PaperAmountReq / 500 >= 1 Then
NumberOf500s = PaperAmountReq \ 500
PaperAmountReq = PaperAmountReq Mod 500
End If
If PaperAmountReq / 100 >= 1 Then
Numberof100s = PaperAmountReq \ 100
PaperAmountReq = PaperAmountReq Mod 100
End If
If PaperAmountReq / 1 = PaperAmountReq Then
NumberOfSingles = PaperAmountReq
End If
'TotalCost = (Convert.ToDouble(Numberof1000s) * PricePer_1000_Sheets) + (Convert.ToDouble(NumberOf500s) * PricePer_500_Sheets) + (Convert.ToDouble(Numberof100s) * PricePer_100_Sheets) + (Convert.ToDouble(NumberOfSingles) * PricePer_1_Sheet)
TotalCost = (Numberof1000s * PricePer_1000_Sheets) + (NumberOf500s * PricePer_500_Sheets) + (Numberof100s * PricePer_100_Sheets) + (NumberOfSingles * PricePer_1_Sheet)
Console.WriteLine("Number of 1000 packages: " & Numberof1000s)
Console.WriteLine("Number of 500 packages: " & Numberof500s)
Console.WriteLine("Number of 100 packages: " & Numberof100s)
Console.WriteLine("Number of singles packages: " & NumberOfSingles)
Console.Write("Total Cost: " & TotalCost)
End Sub
End Module
With this:
If PaperAmountReq / 1000 >= 1 Then
Numberof1000s = PaperAmountReq \ 1000
PaperAmountReq = PaperAmountReq Mod 1000
End If
if you have 1500, you are setting Numberof1000s equal to 1 - not 1000. So when you calculate your total cost, your value of (presumably) cost/sheet is being multiplied by 1 instead of 1000.
Either change your equation here
TotalCost = (Numberof1000s * PricePer_1000_Sheets) + (NumberOf500s * PricePer_500_Sheets) + (Numberof100s * PricePer_100_Sheets) + (NumberOfSingles * PricePer_1_Sheet)
to be something like
TotalCost = (Numberof1000s * PricePer_1000_Sheets * 1000) + (NumberOf500s * PricePer_500_Sheets * 500) + (Numberof100s * PricePer_100_Sheets * 100) + (NumberOfSingles * PricePer_1_Sheet * 1)
or adjust the PricePer_XXX_Sheets values to be the equivalent values.
Dim PricePer_1_Sheet As Double = 0.1
Dim PricePer_100_Sheets As Double = 0.055 * 100
Dim PricePer_500_Sheets As Double = 0.04 * 500
Dim PricePer_1000_Sheets As Double = 0.03 * 1000
Well your numberof variables should be integers or maybe bigintegers if not big enough as should PaperAmountReq
Your code seems to be assuming integer division
in these segments
If PaperAmountReq / 500 >= 1 Then
NumberOf500s = PaperAmountReq \ 500
PaperAmountReq = PaperAmountReq Mod 500
End if
in actual fact because you are using doubles, it's doing floating point division.
I'd also recommend that you use decimal instead of double for your price? and Total Cost variables.
Doubles are very precise, but often very inaccurate.
Looks like you need to convert the NumberOfXXXs variables to sheets, rather than bundles.
Your formula at the end uses per-sheet costs with per-bundle numbers. Either update the costs to be per-bundle, or update the bundle numbers to equal the round number of sheets in that bundle:
TotalCost = NumberOf1000s * 1000 * PricePer_1000_Sheets
Dim PricePer_100_Sheets As Double = 0.055
Dim PricePer_500_Sheets As Double = 0.04
Dim PricePer_1000_Sheets As Double = 0.03
should be
Dim PricePer_100_Sheets As Double = 0.055 * 100
Dim PricePer_500_Sheets As Double = 0.04 * 500
Dim PricePer_1000_Sheets As Double = 0.03 * 1000