Practice Exercises C# Sharp - Learn to program with performing exercises C# Sharp

Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

Switch - Practice Exercises C# Sharp
Practice Exercises C# Sharp4,85320940

Switch - Practice Exercises C# Sharp


Lesson 2:

Flow Control


Exercise 2.30:

Switch


Objetive:

Create a C# program to display the "text mark" corresponding to a certain "numerical mark", using the following equivalence:

9,10 = Sobresaliente
7,8 = Notable
6 = Bien
5 = Aprobado
0-4 = Suspenso

Your program must ask the user for a numerical mark and display the corresponding text mark. You must do it twice: first using "if" and then using "switch".


Source Code:


using System;
public class Exercise048
{
    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;
        }
    }
}
Exercisey 2.30

Share Now:







Privacy Policy:



Google uses associated advertising companies to serve ads when it visits our website. These companies may use the information they obtain from your visits to this and other websites (not including your name, address, email address, or phone number) to provide you with announcements about products and services that interest you. If you would like to learn more about this practice and know your options to prevent these companies from using this information. Click in... Privacy and Terms of Google.

Cookies

This site uses Google cookies to provide its services, to personalize advertisements and to analyze traffic. Google receives information about your use of this website. More information in... Privacy and Terms of Google.