- Course
- Flow controls B
- Switch, break and default
Switch, break and default
Last updated:
8/22/2020
⁃
Difficulty:
Easy
Create a C# program that calculates a student's grade from an integer. Ask the user for a number (x) and answer the following:
- 10 - A+
- 9 - A
- 7,8 - B
- 6 - C
- 5 - E
- 0,4 - F
Use the switch, break and default instruction of C#.
Input
- 10
Output
- A+
Solution
- using System;
- public class BreakAndDefault
- {
- public static void Main(string[] args)
- {
- int x = Convert.ToInt32(Console.ReadLine());
-
- switch (x)
- {
- case 10:
- Console.WriteLine("A+");
- break;
-
- case 9:
- Console.WriteLine("A+");
- break;
-
- case 8:
- case 7:
- Console.WriteLine("B");
- break;
-
- case 6:
- Console.WriteLine("C");
- break;
-
- case 5:
- Console.WriteLine("E");
- break;
-
- default:
- Console.WriteLine("F");
- break;
- }
- }
- }