-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
30 lines (29 loc) · 944 Bytes
/
Copy pathProgram.cs
File metadata and controls
30 lines (29 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class ConditionalOperator
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Please enter a number:");
int number = Convert.ToInt32(Console.ReadLine());
// Using the conditional operator to determine if the number is even or odd
string result = (number % 2 == 0) ? "even" : "odd";
Console.WriteLine($"The number {number} is {result}.");
}
catch (FormatException)
{
Console.WriteLine("Invalid input. Please enter a valid number.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
finally
{
Console.WriteLine("Thank you for using the conditional operator example.");
}
}
}
}