Exercise
Switch
Objetive
Write a Visual Basic (VB.Net) program to display the text grade corresponding to a given numerical grade, using the following equivalence:
9,10 = Excellent
7,8 = Very good
6 = Good
5 = Pass
0-4 = Fail
Your program should ask the user for a numerical grade and display the corresponding text grade. You should do this twice: first using "if" and then using "switch".
Code
Imports System
Public Class Exercise44
Public Shared Sub Main()
Dim number As Integer
Console.Write("Number? ")
number = Convert.ToInt32(Console.ReadLine())
If (number = 9) OrElse (number = 10) Then
Console.WriteLine("Sobresaliente")
ElseIf (number = 7) OrElse (number = 8) Then
Console.WriteLine("Notable")
ElseIf number = 6 Then
Console.WriteLine("Bien")
ElseIf number = 5 Then
Console.WriteLine("Aprobado")
ElseIf (number >= 0) AndAlso (number <= 4) Then
Console.WriteLine("Suspenso")
Else
Console.WriteLine("No válido")
End If
Select Case number
Case 0, 1, 2, 3, 4
Console.WriteLine("Suspenso")
Case 5
Console.WriteLine("Aprobado")
Case 6
Console.WriteLine("Bien")
Case 7
GoTo _Select0_Case8
Case 8
_Select0_Case8:
Console.WriteLine("Notable")
Case 9
Console.WriteLine("Bajo, pero... ")
GoTo _Select0_Case10
Case 10
_Select0_Case10:
Console.WriteLine("Sobresaliente")
Case Else
Console.WriteLine("Nota no válida")
End Select
End Sub
End Class