hey, guys, was wondering if i could get some help with this school assingmnet. no, im not asking for code. more like guidance and clarification. the following is the assignment itself:

You are required to create a Visual Basic application for the Roytec Examinations Department. The program must accept student exam results marked out of 100 via an input box until the value entered is “END”. These values must range between zero (0) and one hundred (100) and must be stored in an array. Invalid values entered must be flagged by a message box which states “Values must be between 0 and 100”. The maximum number of students in any class is 25. (40 marks)
While values are being stored in the array the program must keep track of the number of scores in the
(1) “A” range (90-100)
(2) “B” range (80-89)
(3) “C” range (70-79)
(4) “D” range (60-69)
(5) “F” range (below 60)
Also, the highest score, lowest score, the average (mean) score, the percentage of the grades that fall above the average and the number of invalid entries must be calculated and displayed in the GUI.
Please Note:
a) You must use a Do loop count the number of grades.
b) You must use a case statement to count how many grades are in each range.
c) The number of grades should be stored as a variable and used in the calculation of the average
You are also required to document:
a) Snippets of pseudocode for
i) The validation check.
ii) Storing the values in the array.
iii) Counting the number of invalid entries, and total number of entries.
iv) Counting number of scores in each range.
v) Calculating the highest, lowest, average score and percentage above average (25)

and here is my code

Public Class Form1

    Private Sub startButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles startButton.Click

        Dim grades(25) As Integer
        Dim grade As Integer

        Dim grad As Integer
        Dim aCount As Integer = 0
        Dim bCount As Integer = 0
        Dim cCount As Integer = 0
        Dim dCount As Integer = 0
        Dim fCount As Integer = 0
        Dim highest As Integer
        Dim lowest As Integer = 999


        For i As Integer = 0 To 5


            grade = InputBox("Values must be between 0 and 100 ", "Please enter student grades:")
            Integer.TryParse(grade, grad)

            grades(i) = grad
            Dim invalidcount As Integer = 0

            If grad < 0 Or grad > 100 Then
                MsgBox("Values must be between 0 and 100")

                invalidcount = invalidcount + 1



            End If

            If grad >= 90 Or grad = 100 Then
                aCount = aCount + 1

            End If

            If grad >= 89 Or grad = 80 Then
                bCount = bCount + 1
            End If
            If grad >= 79 Or grad = 70 Then
                cCount = cCount + 1

            End If
            If grad >= 69 Or grad = 60 Then
                dCount = dCount + 1

            End If
            If grad < 60 And grad > 0 Then
                fCount = fCount + 1

            End If




            If grad > highest And grad <= 100 Then
                highest = grad

            ElseIf grad < lowest And grad >= 0 Then
                lowest = grad

            End If


            invalidTextBox.Text = invalidcount.ToString
        Next

        highestTextBox.Text = highest.ToString
        lowestTextBox.Text = lowest.ToString


        outputLabel.Text = aCount.ToString & "students made As, " & bCount.ToString & " made Bs, " & cCount.ToString & "made Cs, " & dCount.ToString & "made Ds' " & fCount.ToString & "made Fs"
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

        Me.Close()

    End Sub

    Private Sub clearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearButton.Click

        invalidTextBox.Text = String.Empty

        lowestTextBox.Text = String.Empty

        highestTextBox.Text = String.Empty



    End Sub
End Class

the problems im having : my counter for the number of invalid entries does not work. it incriments once and thats it.

im not sure how to impliment do...while loops into an array as sir never covered that with us

not completely sure on how to take out the marks stores to find a percentage for above average, nor am i sure on how to check for the mean.

Untitled83
attached is my gui.
any help or input would be a ppreciated. while waiting on a reply i will continue my search for solutions to my probelms online.
thanks in advance.

Edited 4 Years Ago by pritaeas: Moved to vb.net

Dim invalidcount As Integer = 0

line 25, you are reseting the interger for invalidcount to 0 within the loop, move that line above line 18, outside the loop, and you should be good.

On a side note, based on your description, I assume your loop should be up to 25, not 5, as max 25 in the class?

First you get the "sermon". Since you are required to write pseudocode anyway, write it first, then prefix each line of pseudocode with a single quote. There. You have just created all of your code comments. Now add the actual code. End of sermon.

Now a few suggestions.

InputBox("Values must be between 0 and 100 ", "Please enter student grades:")

returns a String, not an Integer so assign the data to a String value.

Integer.TryParse(grade, grad)

will return a value of 0 if the user enters non-numeric input. Your code won't be able to tell if the user has entered "0" (which is valid) or "jabberwocky" (which is not). I suggest you first determine if the input data is numeric. You can do that as follows:

Dim input As String = InputBox("Values must be between 0 and 100 ", "Please enter student grades:")

If IsNumeric(input) And InStr(input, ".") = 0 Then
    Integer.TryParse(input, grade)
Else
    'the data entered was not an integer number
End If

Note that the above doesn't validate beyond ensuring that the input can be converted to an integer value with no loss of precision. You still have to ensure that it falls between 0 and 100. If you have determined that the input is not valid, don't do any of the grade calculations. Your code continues with the calculations even if the input is bad.

Your range checks are inefficient. The test

If grade >= 90 Or grad = 100 Then

could be written as

If grade >= 90 Then

Also, every value is tested for every range. If the grade, for example, is 95, you still check all ranges even though after the first check you have determined that it is an "A" grade. Assuming you have already determined that the grade is a number from 0 to 100, a better way to check ranges is with a select clause as follows:

Select Case grade
    Case Is >= 90
        aCount += 1
    Case Is >= 80
        bCount += 1
    Case Is >= 70
        cCount += 1
    Case Is >= 60
        dCount += 1
    Case Else
        fCount += 1
End Select

So in its simplest form your inner structure should be

if the input is a number from 0 to 100 then
    save and process the grade
else
    do invalid data processing
end if

Plus what WetCoastLife said about resetting the counter inside the loop. So give these suggestions some thought and see where that takes you.

Edited 4 Years Ago by Reverend Jim

thanks for the feedback guys
sad to say the deadline has passed. but i am determined to make this work just because.
i will keep you all updated on my progress

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