Is what im trying to do possible?

NerdyGurl

Member
Joined
Apr 19, 2007
Messages
7
Location
Auckland, NZ
Programming Experience
Beginner
Hi Im trying to create a simple console application the question ill post below to try to clarify what im trying to do within the program.
A sales person gets paid by commision 9% of there gross sales and also get $200 ive gotta work out how many people earned salaries within these ranges using an array (200-299,300-399,400-499 etc)

What im trying to do but im not sure if its possible is within the For..Next statement I want to be able to compare the salary by the salaryRanges and then add one to the count of answer?? I have the salaryRange as my array but i cant seem to work out how to do the equation i need within the For..Next statement.

VB.NET:
Module SalesCompany

Sub main()

Dim Id As Integer
Dim salesGross As Integer
Dim salary As Integer

Console.writeline("Enter ID")
Id = Console.readline()
Console.writeline("Enter sales gross")
salesGross = Console.readline()

salary = (salesGross - 9%) + 200

Dim salaryRange As Integer() = New Integer() {200-299,300-399,400-499,_
500-599,600-699,700-799,800-899,900-999}

For answer As Integer = 0 To salaryRange.GetUpperBound(0)
(piece i cant work out to use salary to add a count to answer by salaryRange)
Next

End Sub

End Moule

Any help or advice would be appreciated :)
 
Integer 200-299 = -99 and not a range. VB.Net doesn't have a "range" class or structure but you can use for example a Point and pretend X is lower bound and Y is upper bound of the range, then check if your number is greater than point.X and less than point.Y.

(salesGross + 9%) can't be written like that in programming currently, do (salesGross +salesGross*9/100) or (salesGross*1.09)
 
Since you want to count number of people for each range, your range structure/class needs one more member, the Count, so pretending with the Point would be pointless actually. So you could write your Range class like below, you might as well add a method to check if a number is within the range right away:
VB.NET:
    Class Range
        Public Lower, Upper, Count As Integer
        Public Sub New(ByVal lower As Integer, ByVal upper As Integer)
            Me.Lower = Lower
            Me.Upper = upper
        End Sub
        Public Function WithinRange(ByVal number As Integer) As Boolean
            If number >= Me.Lower AndAlso number <= Upper Then
                Return True
            Else
                Return False
            End If
        End Function
    End Class
Notice also the constructor added that makes it easier to create one range like this:
VB.NET:
Dim r As New Range(200, 299)
Instead of having to do this tedious work for each range:
VB.NET:
Dim r As New Range()
r.Lower = 200
r.Upper = 299
Keep all the ranges is a List(Of T):
VB.NET:
Dim ranges As New List(Of Range)
ranges.Add(New Range(200, 299))
ranges.Add(New Range(300, 399))
ranges.Add(New Range(400, 499))
When you want to check all the salaries and count how many in each range you do this or similar that fit the bill:
VB.NET:
        Dim salary As Integer = 234
        For Each r As Range In ranges
            If r.WithinRange(salary) Then
                r.Count += 1
                Exit For
            End If
        Next
If you checked all the ranges now you would see that the first one (range 200 to 299) had a count of one the the others a count of zero.
Hope this gives you some ideas in the right direction.
 
Back
Top