I wrote a console application that shows a survey of salespeople that earn a salary in a certain range based on their grossSales.

I am not getting the right results.

A salesperson makes $200 plus 9% commission on grossSales.

when I enter $5000 grossSales I get the result of the range
$700 - $799 and not

$600 - $699

(($5000 * 9)/ 100 ) + $200 = $650

What am I doing wrong.

Module Module1


Sub Main()
Dim index As Integer
Dim salary As Integer
Dim grossSales As Integer = 1



Dim salaryRange() As Integer = New Integer(10) {}


Console.WriteLine("Program to find number of salesmen in a salary range")
Console.WriteLine("Enter the salesman's gross sales(0 to end) : ")
grossSales = Console.ReadLine()
While (grossSales <> 0)
salary = 200 + ((9 * grossSales) / 100)
index = (salary / 100) - 1
If salary > 1000 Then
salaryRange(9) = salaryRange(9) + 1
Else
salaryRange(index) = salaryRange(index) + 1
End If


Console.WriteLine("Enter the salesman's gross sales(0 to end)")
grossSales = Console.ReadLine()
End While



For i = 0 To 8
Console.WriteLine("$" & i * 100 + 200 & "-$" & i * 100 + 299 & " is " & salaryRange(i + 1))
Next i
Console.WriteLine("$1000 and over " & salaryRange(8))


End Sub

Edited 3 Years Ago by happygeek: fixed formatting

You need to change the line:
Console.WriteLine("$" & i * 100 + 200 & "-$" & i * 100 + 299 & " is " & salaryRange(i + 1))

to

Console.WriteLine("$" & i * 100 & "-$" & i * 100 + 99 & " is " & salaryRange(i))

Since you added the 200 from before, you don't need to add it here. Also, there is no need to increment the salaryRange by 1.

thank you that worked!!!

i have another console application I am having trouble with. It for an Airline Reservation System

I keep getting Index OutofBounds error but I can not find it for the life of me.
Here is its

Module Module1



    Sub Main()
        Dim seats As Integer() = New Integer(10) {}
        Dim ch As Char = "0"
        Dim status As Integer

        For seat = 0 To 8
            seats(seat) = 0


        Next

        Console.WriteLine("Airline Reservation System")

        While ch <> "3"
            Console.WriteLine(vbTab(3) & "Menu" & vbNewLine)
            Console.WriteLine("FirstClass:  1 ")
            Console.WriteLine("Economy : 2 ")
            Console.WriteLine("Exit: 3 ")
            Console.WriteLine("Enter your option: ")
            ch = Console.ReadLine()

            If ch = "1" Then
                status = firstClass(seats)
                If status < 5 Then
                    seats(status) = 1
                    Console.WriteLine("Your seat number is: " & status + 1)
                Else
                    Console.WriteLine("No availability in first clas")
                    Console.WriteLine("Would you like to travel in economy class (Y/N)?")
                    ch = Console.ReadLine()
                    If ch = "Y" Then
                        status = economy(seats)
                        If status < 8 Then
                            seats(status) = 1
                            Console.WriteLine("Your seat number is:" & status + 1)
                        Else
                            Console.WriteLine("Next flight leaves in 3 hours.")


                        End If
                    End If


                End If
            End If

            If ch = "2" Then
                status = economy(seats)
                If status < 8 Then
                    seats(status) = 1
                    Console.WriteLine("Your seat number is " & status + 1)
                Else
                    Console.WriteLine("No availability in economy class")
                    Console.WriteLine("Would you like to trave in first class (Y/N)")
                    ch = Console.ReadLine()
                    If ch = "Y" Then
                        status = firstClass(seats)

                        If status < 4 Then
                            seats(status) = 1
                            Console.WriteLine("Your seat number is " & status + 1)
                        Else
                            Console.WriteLine("Next flight leaves in 3 hours")

                        End If
                    End If
                End If
            End If
        End While
    End Sub

    Function firstClass(ByVal seats() As Integer) As Integer
        Dim currentSeat As Integer

        For currentSeat = 0 To 4
            If seats(currentSeat) = 0 Then
                Continue For

            End If
        Next
        Return currentSeat
    End Function

    Function economy(ByVal seats() As Integer) As Integer
        Dim currentSeat As Integer
        For currentSeat = 5 To 8
            If seats(currentSeat) = 0 Then
                Continue For
            End If
        Next
        Return currentSeat

    End Function

End Module

Then I got so mixed up I probably put the End If wrong.

What is wrong with this code???

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Try replacing the line
Console.WriteLine(vbTab(3) & "Menu" & vbNewLine)
with
Console.WriteLine(vbTab & "Menu" & vbNewLine)

This article has been dead for over six months. Start a new discussion instead.