微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

是否使用 while 循环或直到循环?哪一个适合我的代码?

如何解决是否使用 while 循环或直到循环?哪一个适合我的代码?

问题:

a) 创建一个名为 intMarks 的数组来存储所有 10 名学员的测试结果。

b) 提示用户将结果输入到问题 a) 中创建的数组中,

c) 计算通过测试的学员人数。假设及格分数为 50%。

d) 打印最高分和通过测试的学员人数。

提示用户输入结果”没有问题。

但是'统计通过测试的学员人数'和'打印最高分'的输出值是错误的。

这是我的代码

Sub Main(args As String())
    Dim intMarks,intHighest,count As Integer
    Dim isValid As Boolean
    Dim intTra,maxTra As Integer
    Dim countNum As Integer = 0

    isValid = False

    Do
        Console.WriteLine("Enter the number of trainees: ")
        maxTra = Console.ReadLine

        For intTra = 1 To maxTra
            Console.WriteLine("Enter the mark between 0-100: ")
            intMarks = Console.ReadLine
            Console.WriteLine("The mark of trainee " & intTra & " is: " & intMarks)
        Next
        Console.WriteLine()

        If intMarks > 50 Then
            countNum += 1
        End If
        Console.WriteLine("Have " & countNum & " trainees has passed the test by 50%.")
        Console.WriteLine()

        intHighest = intMarks
        If intHighest > intMarks Then
            intHighest = intTra
        End If
        Console.WriteLine("The trainee " & intTra & " has got the highest marks.")
    Loop While (isValid = True)
End Sub

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。