Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp exercises: Determine a specific age is eligible for casting the vote


C# Sharp Conditional Statement : Exercise-5 with Solution

Write a C# Sharp program to read age of a candidate and determine whether it is eligible for casting his/her own vote.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise5  
{  
    public static void Main() 
{
  int vote_age;
    Console.Write("\n\n");
    Console.Write("Detrermine a specific age is eligible for casting the vote:\n");
    Console.Write("----------------------------------------------------------");
    Console.Write("\n\n");


    Console.Write("Input the age of the candidate : ");
    vote_age= Convert.ToInt32(Console.ReadLine());
  if (vote_age<18)
     {
       Console.Write("Sorry, You are not eligible to caste your vote.\n");
       Console.Write("You would be able to caste your vote after {0} year.\n\n",18-vote_age);
     }
  else
     Console.Write("Congratulation! You are eligible for casting your vote.\n\n");
}
}

Sample Output:

Detrermine a specific age is eligible for casting the vote:                                                   
----------------------------------------------------------                                                                                                   
Input the age of the candidate : 18                                                                           
Congratulation! You are eligible for casting your vote. 

Pictorial Presentation:

Conditional Statement: Detrermine a specific age is eligible for casting the vote.

Flowchart:

Flowchart: Detrermine a specific age is eligible for casting the vote.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to find whether a given year is a leap year or not.
Next: Write a C# Sharp program to read the value of an integer m and display the value of n is 1 when m is larger than 0, 0 when m is 0 and -1 when m is less than 0.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.