Proposed exercise
Create a C# program to display the "text mark" corresponding to a certain "numerical mark", using the following equivalence:
- 9,10 = Excellent
- 7,8 = Notable
- 6 = Good
- 5 = Pass
- 0-4 = Fail
You must do it twice: first using "if" and then using "switch".
Output
Solution
using System; public class CalificationSwitch { public static void Main() { int calification; Console.Write("Enter a calification: "); calification = Convert.ToInt32(Console.ReadLine()); if ((calification == 9) || (calification == 10)) Console.WriteLine("Excelent"); else if ((calification == 7) || (calification == 8)) Console.WriteLine("Notable"); else if(calification == 6) Console.WriteLine("Good"); else if(calification == 5) Console.WriteLine("Pass"); else if ((calification >= 0) && (calification <= 4)) Console.WriteLine("Fail"); else Console.WriteLine("Not valid"); switch(calification) { case 0: case 1: case 2: case 3: case 4: Console.WriteLine("Fail"); break; case 5: Console.WriteLine("Pass"); break; case 6: Console.WriteLine("Good"); break; case 7: case 8: Console.WriteLine("Notable"); break; case 9: case 10: Console.WriteLine("Excelent"); break; default: Console.WriteLine("Not valid"); break; } } }