无法打印输入VB

时间:2018-04-09 07:58:58

标签: vb.net

我的问题是关于尝试打印用户输入的数字,但它总是为Maxno和Minno打出0 0 0。这就是我所有的尝试,希望我能得到任何帮助。我不确定如何改进它所以我来这里寻求帮助。

Imports System

Public Module Module1

Public Sub Main()
    Const MSG_ENTRYNAME = "Please enter the name of the student."
    Const MSG_ERROR = "Score not valid, please enter again."
    Const MSG_ENTRYDATA = "Please enter the score of the respective student."
    Dim marks(10) as Decimal
    Dim name(10) as STRING
    Dim sum as Decimal
    Dim count as INTEGER
    Dim mean as INTEGER
    Dim maxNo as Decimal
    Dim minNo as Decimal
    Dim maxcount as INTEGER
    Dim mincount as INTEGER
    Dim maxName as STRING
    Dim minName as STRING
    Dim maxIndex as INTEGER
    Dim minIndex as INTEGER
    for i = 0 To 2
        Console.WriteLine(MSG_ENTRYNAME)
        name(i) = Console.ReadLine
        Console.WriteLine(MSG_ENTRYDATA)
        marks(i) = Console.ReadLine
        while marks(i) < 25 or marks(i) > 100
            Console.WriteLine(MSG_ERROR)
            Marks(i) = Console.Readline
        end while
    next

    for i = 0 to marks.Length - 1
        if marks(i) > maxNo then
            marks(i) = maxNo
        end if

        minNo = marks(i)
        if marks(i) < minNO then
            minNo = marks(i)
        end if

        sum = +marks(i)
    next

    Console.WriteLine(MaxNo)
    Console.WriteLine(MinNo)
    Console.WriteLine(sum)
End Sub

结束模块

1 个答案:

答案 0 :(得分:0)

您的代码有一些简单的逻辑错误。请检查下面的固定代码。

minNo = marks(i)                    'added 
For i = 0 to 2                      'changed
    If marks(i) > maxNo Then
        maxNo = marks(i)             'changed
    End If

    'minNo = marks(i)                'removed
    If marks(i) < minNo Then
        minNo = marks(i)
    End If

    sum += marks(i)                   'changed
Next