Exercise
Switch
Objetive
Create a C# 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".
Example Code
using System;
public class Exercise44
{
public static void Main()
{
int number;
Console.Write("Number? ");
number = Convert.ToInt32(Console.ReadLine());
if ((number == 9) || (number == 10))
Console.WriteLine("Sobresaliente");
else if ((number == 7) || (number == 8))
Console.WriteLine("Notable");
else if (number == 6)
Console.WriteLine("Bien");
else if (number == 5)
Console.WriteLine("Aprobado");
else if ((number >= 0) && (number <= 4))
Console.WriteLine("Suspenso");
else
Console.WriteLine("No válido");
switch (number)
{
case 0:
case 1:
case 2:
case 3:
case 4:
Console.WriteLine("Suspenso");
break;
case 5:
Console.WriteLine("Aprobado");
break;
case 6:
Console.WriteLine("Bien");
break;
case 7: goto case 8;
case 8:
Console.WriteLine("Notable");
break;
case 9:
Console.WriteLine("Bajo, pero... ");
goto case 10;
case 10:
Console.WriteLine("Sobresaliente");
break;
default:
Console.WriteLine("Nota no válida");
break;
}
}
}