Vowel - If - 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 a vowel (in lowercase), a digit, or any other symbol, using the if statement. The program should evaluate the user's input and provide an appropriate response based on the category to which the symbol belongs. Using the if statement will allow you to make decisions based on the defined conditions, which is fundamental to programming logic.

This exercise is excellent for learning to work with conditionals in C#, enabling you to make decisions within your program based on the type of data entered. It is also useful for familiarizing yourself with character manipulation, such as checking if the symbol is a vowel, a digit, or a special character.

The if statement is one of the most important structures in programming because it allows programs to make decisions based on user input, and this exercise is a great way to practice using it.

 Category

Basic Data Types

 Exercise

Vowel - If

 Objective

Write a C# program to ask the user for a symbol and respond if it's a vowel (in lowercase), 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 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();

        // Check if the symbol is a vowel
        if (symbol == 'a' || symbol == 'e' || symbol == 'i' || symbol == 'o' || symbol == 'u')  // If the symbol is a vowel
        {
            Console.WriteLine("It is a vowel.");  // Display message for vowel
        }
        // Check if the symbol is a digit
        else if (symbol >= '0' && symbol <= '9')  // If the symbol is a digit (from '0' to '9')
        {
            Console.WriteLine("It is a digit.");  // Display message for digit
        }
        else  // If the symbol is neither a vowel nor a digit
        {
            Console.WriteLine("It is another symbol.");  // 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#.

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

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