Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Vb.net calculation problem.

Posted on 2009-03-31
4
Medium Priority
?
273 Views
Last Modified: 2012-05-06
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.
'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

Open in new window

0
Comment
Question by:shaunareno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:shaunareno
ID: 24035832
Revised Question:
not the calculation but, the logic is what I'm having trouble with.

0
 
LVL 84

Expert Comment

by:ozo
ID: 24036112
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
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24036207
It seems like from your line here:

    bookPoints = (3 * BOOKS_READ2Integer) + (3 * BOOKS_READ2Integer) + (numberBooksRead - 6) * (BOOKS_READ3Integer)

That you could instead loop thru and just tally up the points as you go:

    Private Function CalculateBookPoints() As Integer
        Dim points As Integer = 0
        Dim numberBooksRead As Integer = Integer.Parse(numBooksReadTextBox.Text)
        For i As Integer = 1 To numberBooksRead
            If i <= 3 Then
                points = points + BOOKS_READ1Integer
            ElseIf i <= 6 Then
                points = points + BOOKS_READ2Integer
            Else
                points = points + BOOKS_READ3Integer
            End If
        Next
        Return points
    End Function
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Six Sigma Control Plans
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question