EDN Admin
Well-known member
Hi. Im having trouble with a program that should be fairly simple. What its supposed to do is determine the price of an item based on how many there are. Every time it exceeds a certain amount of items however, the cost drops 5 cents.
It works fine up until 10, the first thresh hold. Then it just seems to drop off everything to the left of the decimal point for the numbers after. To clarify, What I mean is that when it says 5.00 when I enter ten, that would be correct, but
when I enter 11 it only says .45 when 5.45 should be the correct answer. This repeats at the second thresh hold, at 50. Does anybody know what I could do?<span style="font-size:small <span style="font-size:small
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Declare the variables
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsEnteredInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsZeroToTenInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsElevnToFiftyInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim AdditionalWidgetsInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim PriceDecimal <span style="color:blue
As <span style="color:blue Decimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetZeroToTenDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.5D
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetElevenToFiftyDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.45D
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim AdditionalWidgetDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.4D
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub Calculate()
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Convert widgets ordered to numeric and assign to a variable
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
WidgetsEnteredInteger = <span style="color:blue Integer.Parse(WidgetsPurchasedTextBox.Text)
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Divide the entered number of widgets into three groups
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue If WidgetsEnteredInteger <= 10 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> WidgetsZeroToTenInteger = WidgetsEnteredInteger
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger <= 50 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
WidgetsElevnToFiftyInteger = WidgetsEnteredInteger - 10
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger <= 200 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
AdditionalWidgetsInteger = WidgetsEnteredInteger - 50
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue If
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Determine the price based on how many widgets are entered
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue If WidgetsEnteredInteger < 10 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = WidgetsZeroToTenInteger * WidgetZeroToTenDecimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger < 50 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = WidgetsZeroToTenInteger * WidgetZeroToTenDecimal + WidgetsElevnToFiftyInteger * WidgetElevenToFiftyDecimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger < 200 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = (WidgetsZeroToTenInteger * WidgetZeroToTenDecimal) + (WidgetsElevnToFiftyInteger * WidgetElevenToFiftyDecimal) + (AdditionalWidgetsInteger * AdditionalWidgetDecimal)
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue If
<br/>
<br/>
View the full article
It works fine up until 10, the first thresh hold. Then it just seems to drop off everything to the left of the decimal point for the numbers after. To clarify, What I mean is that when it says 5.00 when I enter ten, that would be correct, but
when I enter 11 it only says .45 when 5.45 should be the correct answer. This repeats at the second thresh hold, at 50. Does anybody know what I could do?<span style="font-size:small <span style="font-size:small
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Declare the variables
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsEnteredInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsZeroToTenInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetsElevnToFiftyInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim AdditionalWidgetsInteger <span style="color:blue
As <span style="color:blue Integer
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim PriceDecimal <span style="color:blue
As <span style="color:blue Decimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetZeroToTenDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.5D
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim WidgetElevenToFiftyDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.45D
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Dim AdditionalWidgetDecimal <span style="color:blue
As <span style="color:blue Decimal = 0.4D
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue Private <span style="color:blue Sub Calculate()
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Convert widgets ordered to numeric and assign to a variable
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
WidgetsEnteredInteger = <span style="color:blue Integer.Parse(WidgetsPurchasedTextBox.Text)
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Divide the entered number of widgets into three groups
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue If WidgetsEnteredInteger <= 10 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span> WidgetsZeroToTenInteger = WidgetsEnteredInteger
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger <= 50 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
WidgetsElevnToFiftyInteger = WidgetsEnteredInteger - 10
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger <= 200 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
AdditionalWidgetsInteger = WidgetsEnteredInteger - 50
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue If
<p style="line-height:normal; margin-bottom:0pt
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:green Determine the price based on how many widgets are entered
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue If WidgetsEnteredInteger < 10 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = WidgetsZeroToTenInteger * WidgetZeroToTenDecimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger < 50 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = WidgetsZeroToTenInteger * WidgetZeroToTenDecimal + WidgetsElevnToFiftyInteger * WidgetElevenToFiftyDecimal
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue ElseIf WidgetsEnteredInteger < 200 <span style="color:blue
Then
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
PriceDecimal = (WidgetsZeroToTenInteger * WidgetZeroToTenDecimal) + (WidgetsElevnToFiftyInteger * WidgetElevenToFiftyDecimal) + (AdditionalWidgetsInteger * AdditionalWidgetDecimal)
<p style="line-height:normal; margin-bottom:0pt <span style="font-family:Consolas; font-size:9.5pt <span>
<span style="color:blue End <span style="color:blue If
<br/>
<br/>
View the full article