Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
VB
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
Posted
Updated 1-Feb-14 17:29pm
v3

Try this

VB
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
 
Share this answer
 
v2
Comments
Abhinav S 1-Feb-14 22:46pm    
I don't think its a compile error.
Karthik_Mahalingam 1-Feb-14 22:48pm    
Abinav,
its a compile error ,
finalGrade is not declared..
Abhinav S 1-Feb-14 22:50pm    
However, there could be another scenario where this value remains empty.
Karthik_Mahalingam 1-Feb-14 22:55pm    
even though,it is empty or null , the output will be printed as Final Grade: "
so its a compile error , not run time error..
Abhinav S 1-Feb-14 23:25pm    
Agreed. However, if the total score is 594, the finalGrade will be empty.
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
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900