-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
59 lines (52 loc) · 1.84 KB
/
Program.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
class Program
{
static void Main()
{
Console.WriteLine("Simple Console Calculator");
Console.WriteLine("Select an operation:");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Division");
Console.Write("Enter choice (1/2/3/4): ");
string choice = Console.ReadLine();
Console.Write("Enter first number: ");
double num1 = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter second number: ");
double num2 = Convert.ToDouble(Console.ReadLine());
double result = 0;
switch (choice)
{
case "1":
result = num1 + num2;
Console.WriteLine($"Result: {num1} + {num2} = {result}");
break;
case "2":
result = num1 - num2;
Console.WriteLine($"Result: {num1} - {num2} = {result}");
break;
case "3":
result = num1 * num2;
Console.WriteLine($"Result: {num1} * {num2} = {result}");
break;
case "4":
if (num2 != 0)
{
result = num1 / num2;
Console.WriteLine($"Result: {num1} / {num2} = {result}");
}
else
{
Console.WriteLine("Error: Division by zero is not allowed.");
}
break;
default:
Console.WriteLine("Invalid choice.");
break;
}
// Wait for the user to press a key before closing
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}