Visual Basic Else If - PullRequest
       2

Visual Basic Else If

0 голосов
/ 22 сентября 2018

Я выполняю задание для класса «Введение в бизнес программирование».Он использует Visual Basic 2017. У нас должна быть программа, которая отслеживает оценки учащихся, используя цикл do while и другие операторы if.Профессор поручил нам завершить цикл, введя -1 в поле ввода, но его нельзя использовать в расчетах.Это то, что у меня есть, и оно не работает.

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

Я не включил переменные, потому что этот пост будет очень длинным.Я не уверен, почему -1 все еще вычисляется.Есть идеи?Заранее спасибо!

1 Ответ

0 голосов
/ 22 сентября 2018

Цикл Do...While проверяет только условие в конце.

Запускает итерацию цикла, затем получает оценку теста.

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

Затем выполняется телоцикла, пока не дойдет до конца, где он увидит, что счет равен -1, и выйдет из цикла.

Еще один способ записать это - бесконечный запуск цикла.

Do
    //Body
Loop While True

И затем проверка, является ли Счет -1, и выход из цикла.

If intTestScore = -1
    Exit Do
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...