-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
33 lines (32 loc) · 945 Bytes
/
Copy pathProgram.cs
File metadata and controls
33 lines (32 loc) · 945 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
31
32
33
class Methods
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Please enter a number to calculate its square:");
int number = Convert.ToInt32(Console.ReadLine());
int result = CalculateSquare(number);
Console.WriteLine($"The square of {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 square calculation program.");
}
}
static int CalculateSquare(int num)
{
return num * num;
}
}
}