shaunareno
asked on
Vb.net calculation problem.
How am i supposed to set this up? I've tried using what I've got but it won't calculate what I need to properly. Breakdown:
I have a program were I'm supposed to calculate books read and award points
based on a certain amount of books read by the reader. In the place of some numbers I used constants.
1-3 books = 10pts ea.
next 3 books = 15pts ea.
6 or more = 20pts ea.
I have a program were I'm supposed to calculate books read and award points
based on a certain amount of books read by the reader. In the place of some numbers I used constants.
1-3 books = 10pts ea.
next 3 books = 15pts ea.
6 or more = 20pts ea.
'Declared Constants
Const BOOKS_READ1Integer As Integer = 10
Const BOOKS_READ2Integer As Integer = 15
Const BOOKS_READ3Integer As Integer = 20
Const MAX_BOOKS_ALLOWED_READInteger As Integer = 10000
'Declared Variables
Dim totalPointsDecimal, booksReadInteger, bookPoints, _
customerCountInteger, numberBooksReadInteger, totalBooksRead, _
numbooksRead, average, booksRead As Integer
Private Function calculatePointsDataType(ByVal bookValue As String) As Integer
Dim bookPoints As Integer
Try
Dim numberBooksRead As Integer = Integer.Parse(numBooksReadTextBox.Text)
If numberBooksRead <= 1 And 3 Then
bookPoints = numberBooksRead * BOOKS_READ1Integer
ElseIf numberBooksRead < 3 And = 6 Then
bookPoints = 3 * BOOKS_READ1Integer + numberBooksRead - 3 * BOOKS_READ2Integer
ElseIf numberBooksRead >= 6 And MAX_BOOKS_ALLOWED_READInteger Then
bookPoints = (3 * BOOKS_READ2Integer) + (3 * BOOKS_READ2Integer) + (numberBooksRead - 6) * (BOOKS_READ3Integer)
End If
Catch ex As Exception
End Try
Return bookPoints
End Function
what are you trying to do when you say
And 3
?
what are you trying to do when you say
And = 6
numberBooksRead - 3 * BOOKS_READ2Integer
would be interpreted under customary precedence rules as
numberBooksRead - (3 * BOOKS_READ2Integer)
whereas you probably meant
(numberBooksRead - 3) * BOOKS_READ2Integer
And 3
?
what are you trying to do when you say
And = 6
numberBooksRead - 3 * BOOKS_READ2Integer
would be interpreted under customary precedence rules as
numberBooksRead - (3 * BOOKS_READ2Integer)
whereas you probably meant
(numberBooksRead - 3) * BOOKS_READ2Integer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
not the calculation but, the logic is what I'm having trouble with.