If, Symbols - C# Programming Exercise

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, or any other symbol, using an if control structure. The program should identify the type of character entered by checking first if the symbol is an uppercase or lowercase vowel, then if it is a number, and if it doesn’t meet any of these conditions, it should classify it as any other symbol. This exercise is useful for practicing the use of if conditionals and learning how to handle different types of characters efficiently.

When writing this program, you should make use of the char function to compare characters and decide which category the entered symbol belongs to. This type of exercise is ideal for understanding how conditions work in programming, especially in scenarios involving checking simple data types like letters and numbers.

Additionally, it’s a great way to practice handling characters, which is essential for developing programs that efficiently process text inputs.

 Category

Basic Data Types

 Exercise

If, Symbols

 Objective

Write a C# program to ask the user for a symbol and answer if is an uppercase vowel, a lowercase vowel, a digit or any other symbol, using "if".

 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 the symbol input
        char symbol = Console.ReadKey().KeyChar;  // Read the symbol entered by the user

        // Check if the symbol is an uppercase vowel
        if ("AEIOU".IndexOf(symbol) >= 0)  // If the symbol is in the string "AEIOU"
        {
            Console.WriteLine("\nThe symbol is an uppercase vowel.");  // Display message for uppercase vowel
        }
        // Check if the symbol is a lowercase vowel
        else if ("aeiou".IndexOf(symbol) >= 0)  // If the symbol is in the string "aeiou"
        {
            Console.WriteLine("\nThe symbol is a lowercase vowel.");  // Display message for lowercase vowel
        }
        // Check if the symbol is a digit
        else if (Char.IsDigit(symbol))  // If the symbol is a digit
        {
            Console.WriteLine("\nThe symbol is a digit.");  // Display message for digit
        }
        // If none of the above conditions are true, it's any other symbol
        else
        {
            Console.WriteLine("\nThe symbol is neither a vowel nor a digit.");  // Display message for other symbols
        }
    }
}

 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#.

  •  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 -...

  •  Perimeter Area

    In this C# exercise, you are asked to write a program that calculates the perimeter, area, and diagonal of a rectangle from its width and height....

  •  Hexadecimal and binary

    In this C# exercise, you are asked to write a program that prompts the user for a number and displays it in both hexadecimal and binary. The program should continue r...

  •  Binary

    In this C# exercise, you are asked to write a program that prompts the user for a decimal number and displays its equivalent in binary. The program should continue re...

  •  Conditional and boolean

    In this C# exercise, you are asked to write a program that uses the conditional operator (also known as the ternary operator) to assign a boolean variable named "bothEven...