从字符串“”到类型 'Double' 的转换在 .NET Fiddle 的 VB 中无效

Conversion from string "" to type 'Double' is not valid In .NET Fiddle's VB

我正在学校写一个项目(在 .NET Fiddle 的 VB 控制台上)并且遇到错误。

在这个任务中,我们必须: 输入 10 个带有学生姓名的测试结果。 在输入时验证所有数据并拒绝不良数据 我们需要打印出平均值(算术平均值)、最高分和谁得到它(假设每次测试最多 1 个)、最低分和谁得到它(假设每次测试 1 分钟)

我的个人代码如下:

Imports System

Public Module Module1
Public Sub Main()
Dim sStudentName As String
Dim iStudentMark As Double
Dim iHighMark As Integer
Dim iLowMark As Integer
Dim iAve As Integer

For List = 1 to 10

    Console.WriteLine("Input A Students Name")
    sStudentName = Console.ReadLine()
    Console.WriteLine("This student's Mark is")
    iStudentMark = Console.ReadLine()


    Do Until 25<= iStudent Or iStudentMark <= 100
        Console.WriteLine("Error. Invalid Percentage. Re-input.")
        iStudentMark = Console.ReadLine()
    Loop

    iAve = iAve + iStudentMark

    If iStudentMark > iHighMark Then
        iHighMark = iStudentMark
        Console.Write("The Highest Percentage has changed. The top score is now " + iStudentMark + " Percent from " + sStudentName)
    End If

    If iStudentMark < iLowMark Then
        iHighMark = iStudentMark
        Console.Write("The Highest Percentage has changed. The top score is now " + iStudentMark + " Percent from " + sStudentName)
    End If

Next 
iAve = iAve/10
Console.WriteLine(iAve)

End Sub
End Module

我收到的错误消息 is/are:

Run-time exception (line -1): Conversion from string "The Highest Percentage has chang" to type 'Double' is not valid.

Stack Trace:

[System.FormatException: Input string was not in a correct format.]

[System.InvalidCastException: Conversion from string "The Highest Percentage has chang" to type 'Double' is not valid.]

我从来都不是最擅长编码的,非常感谢那些尝试解决问题的人。

Console.ReadLine() 方法将 return 一个字符串,你不能将它直接分配给 double。您需要将它们转换为双倍。

Console.WriteLine("This student's Mark is")
If Not Integer.TryParse(Console.ReadLine(), iStudentMark) Then
    Console.WriteLine("Invalid input..! failed to convert")
End If
'you can proceed with iStudentMark