samedi 22 septembre 2018

Visual Basic Else If statement

I am doing an assignment for an Intro to Business Programming class. It uses visual basic 2017. We have to have a program that keeps track of student grades using a do while loop and else if statements. The professor tasked us with ending the loop by entering -1 into the input box, but it cannot be used in the calculations. This is what I have and it isn't working.

Do
        'Prompt user for a score
        strInput = InputBox("Enter test Score")

        If Integer.TryParse(strInput, intTestScore) Then

            If intTestScore >= 0 And intTestScore <= 100 Then

                'Calculate running totals for each letter grade
                If intTestScore >= 93 Then
                    'Increase student Count A by  1
                    intStudentCountA += 1
                    'add intTestScore to current score total A
                    intTotalA += intTestScore

                ElseIf intTestScore >= 90 Then
                    'Increase student Count A- by 1
                    intStudentCountAMinus += 1
                    'add intTestScore to current score total A-
                    intTotalAMinus += intTestScore

                ElseIf intTestScore >= 87 Then
                    'Increase student Count B+ by 1
                    intStudentCountBPlus += 1
                    'add intTestScore to current score total B+
                    intTotalBPlus += intTestScore

                ElseIf intTestScore >= 83 Then
                    'Increase student Count B by 1
                    intStudentCountB += 1
                    'add intTestScore to current score total B
                    intTotalB += intTestScore

                ElseIf intTestScore >= 80 Then
                    'Increase student Count B- by 1
                    intStudentCountBMinus += 1
                    'add intTestScore to current score total B-
                    intTotalBMinus += intTestScore

                ElseIf intTestScore >= 77 Then
                    'Increase student Count C+ by 1
                    intStudentCountCPlus += 1
                    'add intTestScore to current score total C+
                    intTotalCPlus += intTestScore

                ElseIf intTestScore >= 73 Then
                    'Increase student Count C by 1
                    intStudentCountC += 1
                    'add intTestScore to current score total C
                    intTotalC += intTestScore

                ElseIf intTestScore >= 70 Then
                    'Increase student Count C- by 1
                    intStudentCountCMinus += 1
                    'add intTestScore to current score total C-
                    intTotalCMinus += intTestScore

                ElseIf intTestScore >= 67 Then
                    'Increase student Count D+ by 1
                    intStudentCountDPlus += 1
                    'add intTestScore to current score total D+
                    intTotalDPlus += intTestScore

                ElseIf intTestScore >= 63 Then
                    'Increase student Count D by 1
                    intStudentCountD += 1
                    'add intTestScore to current score total D
                    intTotalD += intTestScore

                ElseIf intTestScore >= 60 Then
                    'Increase student Count D- by 1
                    intStudentCountDMinus += 1
                    'add intTestScore to current score total D-
                    intTotalDMinus += intTestScore

                ElseIf intTestScore >= 0 Then
                    'Increase student Count F by 1
                    intStudentCountF += 1
                    'add intTestScore to current score total F
                    intTotalF += intTestScore

                End If

            End If
            'running total
            intTotal += intTestScore
            'increase student counter by 1
            intStudentCount += 1


            'add the score to listbox
            lstScore.Items.Add(intTestScore.ToString())

            Else
                MessageBox.Show("The value must be an integer. The maximum possible score is 100.")

        End If

    Loop While intTestScore <> -1

I didn't include the variables because this post would be really really long. I'm not sure why -1 is still being calculated. Any ideas? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire