0

Need to write a script wit the following criteria using VBScript: Am an English teacher and have some programming experience but not to this extent that is needed. Just trying to make it easier on me for grading...

1. prompt user for a # of quiz scores to input, should create an array large enough to hold that # of scores

2. Set loop allowing user to enter approp. # of scores, scores to be entered as integers, each score should be placed in array

3. det. avg score (rounded to an int) for all data

4. det. # of scores are above the average

5. det. # of scores are below the average

6. det. # of scores are equal to average

7. generate message box showing # of quiz scores, avg score, above avg score, below avg score and equal avg score.

Any help would be greatly appreciated!!!!!!!

Edited by reneeschultz: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Tarkenfire
0

Okay, so I know nothing about VBScript, so I went and coded the logic in VB.NET, and I'll research how to convert it to VBScript then re-write it for you. (probably tomorrow, as it is very late right now.)

Here's what it would look like in VB.NET, for reference to explain the logic:

Public Class Form1

    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
        'Get number of quizes
        Dim quizNumber As Integer
        Try
            quizNumber = CInt(InputBox("Enter the number of quizes:", "Enter Data"))
        Catch ex As InvalidCastException
            MsgBox("Box must not be left blank, and only integers may be entered.")
            Exit Sub
        End Try

        'Other Dims. Average needs to be a double since integer division in VB uses truncation rather than rounding
        Dim average, tempTotal As Double
        Dim grades(quizNumber), underCount, overCount, equalCount As Integer

        'loop to input quiz data. Hopefully you only grade with integers, and not half points
        For counter As Integer = 0 To quizNumber - 1
            Try
                grades(counter) = CInt(InputBox("Please enter grade"))
            Catch ex As InvalidCastException
                MsgBox("Box must not be left blank, and only integers may be entered.")
                Exit Sub
            End Try
        Next

        'gets average...with another loop. Average remains a double until final formatting, where it is rounded
        For counter As Integer = 0 To quizNumber - 1
            tempTotal = tempTotal + grades(counter)
        Next
        average = tempTotal / quizNumber

        'determines number of grades above, below, and equal to the average...with another loop
        For counter As Integer = 0 To quizNumber - 1
            If grades(counter) = average Then
                equalCount = equalCount + 1
            ElseIf grades(counter) < average Then
                underCount = underCount + 1
            Else
                overCount = overCount + 1
            End If
        Next

        'Displays output
        MsgBox("Number of quiz scores: " & quizNumber & ". Average Score: " & Math.Round(average, 0) & ". " & Environment.NewLine & "Number of scores below average: " & underCount & ". Number over average: " & overCount & ". Number equal to average: " & equalCount & ".")
    End Sub
End Class

Edited by Tarkenfire: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.