Write a console application and implement the ternary operator to decide whether the
age a user entered after being prompted is allowed to vote or not(given that only citizens
between 18 and 120 years only inclusive can vote). Use exception handling for non-numerical
input.
Answer / Ajay Dangi
Here's an example in C#:
```csharp
using System;
namespace AgeValidator
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Enter your age: ");
string input = Console.ReadLine();
int age = Convert.ToInt32(input);
if (age >= 18 && age <= 120)
Console.WriteLine("You are eligible to vote.");
else
Console.WriteLine("You are not eligible to vote.");
}
catch (FormatException ex)
{
Console.WriteLine("Invalid input. Please enter a valid number.");
}
}
}
}
```
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the use of GC.KeepAlive Method?
What are the different types of assemblies available and their purpose?
What is use of list in c#?
What is the meaning of MSIL?
How to use delegates with events?
Are there functions in c#?
How do I create a dbml file?
If dll and exe files are same it means you can deploy both the files in gac?
What are the various components in crystal reports?
How does c# achieve polymorphism?
What are anonymous functions in c#?
What is ispostback c#?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)