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:
Flowchart:
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.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework