forked from application-development-08664/calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.csharp
More file actions
56 lines (47 loc) · 1.53 KB
/
program.csharp
File metadata and controls
56 lines (47 loc) · 1.53 KB
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
using System;
public class Program
{
public static void Main(string[] args)
{
while (true)
{
Console.Write("Enter first number: ");
int num1 = 0;
while (!int.TryParse(Console.ReadLine(), out num1))
{
Console.WriteLine("Invalid input. Please enter a valid whole number.");
}
Console.Write("Enter second number: ");
int num2 = 0;
while (!int.TryParse(Console.ReadLine(), out num2))
{
Console.WriteLine("Invalid input. Please enter a valid whole number.");
}
string operation;
while (true)
{
Console.Write("Choose operation (+,-,*,/,%,=): ");
operation = Console.ReadLine();
if (operation == "+" || operation == "-" || operation == "*" ||
operation == "/" || operation == "%" || operation == "=")
{
break;
}
else
{
Console.WriteLine("\nIncorrect Operation Used, please try again\n");
}
}
if (operation == "=")
{
Console.WriteLine("\nProgram terminated.");
break;
}
object result = Calculator.Calculate(num1, num2, operation);
if (result != null)
{
Console.WriteLine($"\nResult: {result}\n");
}
}
}
}