所述值尚未设定值 [英] Said value hasn't been set a value

查看:70
本文介绍了所述值尚未设定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Module Module1

    Sub Main()
        Dim firstName As String
        Dim lastName As String
        Dim pointsReceived As Decimal
        Dim scorePercentage As Decimal
        Dim finalGrade As String

        Console.WriteLine("Welcome to the Stundent Grade Calculator. This program will calculate students score percentage and grade score.")
        Console.WriteLine("Please Enter students first name:")
        firstName = Console.ReadLine()
        Console.WriteLine("Please enter students last name:")
        lastName = Console.ReadLine()
        Console.WriteLine("Please enter students points received:")
        pointsReceived = Console.ReadLine()
        If pointsReceived >= 0 And pointsReceived <= 1000 Then
            Console.WriteLine("Good Score")
        Else
            Console.WriteLine("Error")
        End If

        scorePercentage = (pointsReceived / 1000) * 100
        If scorePercentage >= 0 And scorePercentage <= 59 Then
            finalGrade = "F"
            If scorePercentage >= 60 And scorePercentage <= 69 Then
                finalGrade = "D"
                If scorePercentage >= 70 And scorePercentage <= 79 Then
                    finalGrade = "C"
                    If scorePercentage >= 80 And scorePercentage <= 89 Then
                        finalGrade = "B"
                        If scorePercentage >= 90 And scorePercentage <= 100 Then
                            finalGrade = "A"
                        Else
                            Console.WriteLine("Error")
                        End If
                    End If
                End If
            End If
        End If
        Console.WriteLine("Student first name: " & firstName)
        Console.WriteLine("Students last name: " & lastName)
        Console.WriteLine("Students points: " & pointsReceived)
        Console.WriteLine("Calculated Percentage: %" & scorePercentage)
        Console.WriteLine("Final Grade: " & finalGrade)*/Problem is finalGrade 
        Console.ReadLine()

    End Sub

End Module

推荐答案

试试这个



Try this

Dim firstName As String =""
Dim lastName As String =""
Dim pointsReceived As Decimal = 0
Dim scorePercentage As Decimal = 0
Dim finalGrade As String = "" ' this variable is not initialized with a value


您应该始终为变量赋值。如果不是,编译器会抱怨。

如果你真的没有任何默认值来分配,那么这样做:

You should always assign a value to a variable. The compiler will complain if it is not.
If you really do not have any default value to assign, then do this:
Dim finalGrade As String = Nothing


您输入的总分数是多少?什么是计算的百分比?



你的逻辑存在缺陷。

如果分数百分比在59到60或69之间并且70或79和80或89和90,都不会满足任何条件。

这个finalGrade将保持为空。
What total points have you entered? And what is the calculated percentage?

There is a flaw in your logic.
If the score percentage is between 59 and 60 or 69 and 70 or 79 and 80 or 89 and 90, none of the conditions will be met.
This finalGrade will remain empty.


这篇关于所述值尚未设定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆