-
Notifications
You must be signed in to change notification settings - Fork 701
Expand file tree
/
Copy pathProgram.cs
More file actions
93 lines (83 loc) · 2.89 KB
/
Program.cs
File metadata and controls
93 lines (83 loc) · 2.89 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
namespace GithubActionsLab
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("The Quick Calculator");
var loop = true;
while (loop)
{
try
{
Func<string, string, double> operation = null;
Console.WriteLine("1) Add (x+y)");
Console.WriteLine("2) Subtract (x-y)");
Console.WriteLine("3) Multiply (x*y)");
Console.WriteLine("4) Divide (x/y)");
Console.WriteLine("5) Power (x^y)");
Console.WriteLine("6) Quit");
var operationSelection = GetInput("Select your operation: ");
switch (operationSelection)
{
case "1":
operation = Add;
break;
case "2":
operation = Subtract;
break;
case "3":
operation = Multiply;
break;
case "4":
operation = Divide;
break;
case "5":
operation = Power;
break;
case "6":
loop = false;
continue;
default:
throw new ArgumentException("You did not select a valid option!");
}
var x = GetInput("Enter x: ");
var y = GetInput("Enter y: ");
var result = operation(x, y);
Console.WriteLine($"Result: {result}");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
public static string GetInput(string prompt)
{
Console.Write(prompt);
return Console.ReadLine().Trim();
}
public static double Add(string x, string y)
{
return double.Parse(x) + double.Parse(y);
}
public static double Subtract(string x, string y)
{
return double.Parse(x) - double.Parse(y);
}
public static double Multiply(string x, string y)
{
return double.Parse(x) * double.Parse(y);
}
public static double Divide(string x, string y)
{
return double.Parse(x) / double.Parse(y);
}
// Implement this method following a similar pattern as above
public static double Power(string x, string y)
{
throw new NotImplementedException();
}
}
}