The Program in C# Program to Determine Eligibility for casting his/her own vote is given below:
using System;
namespace VoteEligibility
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Codeauri Family,enter your age here to check whether you are eligible for vote or not!: ");
int age = int.Parse(Console.ReadLine());
if (age >= 18)
{
Console.WriteLine("Wow,you are eligible to cast your vote.");
}
else
{
Console.WriteLine("You are not eligible to cast your vote.");
}
Console.ReadLine();
}
}
}
Output:
Hello Codeauri Family,enter your age here to check whether you are eligible for vote or not!:
23
3
Wow,you are eligible to cast your vote.
Pro-Tips💡
Here are the step by step execution of above program:
- The first line
using System;
is a directive that specifies the System namespace to be used in the code, which provides access to various classes and methods of the .NET framework. - The
namespace VoteEligibility
is a container that defines a scope for the classes and other elements within it. - The
class Program
defines a class namedProgram
that contains aMain
method. - The
Main
method is the entry point of the program, which is executed when the program runs. Console.WriteLine("Hello Codeauri Family,enter your age here to check whether you are eligible for vote or not!: ")
writes a prompt to the console asking the user to enter their age.int age = int.Parse(Console.ReadLine());
reads an input from the user and converts it to an integer and assigns it to theage
variable.if (age >= 18)
checks if theage
variable is greater than or equal to 18. If it is, the program enters the if block.Console.WriteLine("Wow,you are eligible to cast your vote.")
writes a message to the console saying the user is eligible to vote.- If the
age
is less than 18, the program enters the else block andConsole.WriteLine("You are not eligible to cast your vote.")
writes a message to the console saying the user is not eligible to vote. Console.ReadLine()
waits for the user to press enter before ending the program.
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.