Vowel - Switch - C# Programming Exercise

In this C# exercise, you are asked to write a program that prompts the user for a symbol and, using the switch statement, determines whether the symbol entered is a vowel (in lowercase), a digit, or any other symbol. The program should evaluate the user's input and respond appropriately based on which category the symbol belongs to. This type of exercise is useful for understanding how the switch statement works and how you can make comparisons for multiple cases. Additionally, you will get familiar with character manipulation and detecting specific types of symbols using control structures.

This exercise is essential for reinforcing your understanding of working with control structures in C# and interacting with the user to process inputs efficiently. It is also great for practicing selection logic, which is common in developing interactive applications and processing user input.

Exercises like this are perfect for those starting with C# programming, as they help you grasp the basics of the switch statement and data classification within larger programs.

 Category

Basic Data Types

 Exercise

Vowel - Switch

 Objective

Write a C# program to ask the user for a symbol and respond whether it is a vowel (in lowercase), a digit, or any other symbol, using "switch".

 Write Your C# Exercise

using System;  // Import the System namespace to use basic classes like Console

class Program  // Define the main class of the program
{
    static void Main()  // The entry point of the program
    {
        // Ask the user to enter a symbol
        Console.Write("Enter a symbol: ");  // Display prompt for symbol input
        char symbol = Console.ReadKey().KeyChar;  // Read a single character input from the user

        // Move to the next line after the symbol input
        Console.WriteLine();

        // Use switch to determine if the symbol is a vowel, digit, or other symbol
        switch (symbol)
        {
            case 'a':  // If the symbol is 'a'
            case 'e':  // If the symbol is 'e'
            case 'i':  // If the symbol is 'i'
            case 'o':  // If the symbol is 'o'
            case 'u':  // If the symbol is 'u'
                Console.WriteLine("It is a vowel.");  // Display message for vowel
                break;

            // Check if the symbol is a digit
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                Console.WriteLine("It is a digit.");  // Display message for digit
                break;

            // If the symbol is neither a vowel nor a digit
            default:
                Console.WriteLine("It is another symbol.");  // Display message for other symbols
                break;
        }
    }
}

 Share this C# exercise

 More C# Programming Exercises of Basic Data Types

Explore our set of C# programming exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of C#. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in C#.

  •  Vowel - if

    In this C# exercise, you are asked to write a program that prompts the user for a symbol and determines if it is a vowel (in lowercase), a digit, or any other ...

  •  Triangle, NorthEast

    In this C# exercise, you are asked to write a program that prompts the user for a width and then displays a triangle where the base has the number of asterisks corresponding...

  •  Prime factors

    In this C# exercise, you are asked to write a program that takes a number entered by the user and displays it as a product of its prime factors. Prime factors are numbers th...

  •  If, symbols

    In this C# exercise, you are asked to write a program that prompts the user for a symbol and determines if it is an uppercase vowel, a lowercase vowel, a digit...

  •  Char + for

    In this C# exercise, you are asked to write a program that prints the letters from B to N in uppercase, using a for loop. This type of exercise is perfect for ...

  •  Double, approximation of Pi

    In this C# exercise, you are asked to write a program that calculates an approximation for PI using the alternating fraction series: pi/4 = 1/1 - 1/3 + 1/5 -...