-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
44 lines (34 loc) · 1.14 KB
/
Program.cs
File metadata and controls
44 lines (34 loc) · 1.14 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
Console.WriteLine("This is a calculator. Please enter your first number:");
double num1 = Double.Parse(Console.ReadLine());
Console.WriteLine("\nPlease enter your operation. The options are as follows:\n\nAdd:\t+\n\nSubtract:\t-\n\nMultiply:\t*\n\nDivide:\t/\n\nMultiply to the Power of:\tP");
string operation = Console.ReadLine();
Console.WriteLine("\nPlease enter your second number:");
double num2 = Double.Parse(Console.ReadLine());
double answer;
switch (operation.ToLower())
{
case "+":
answer = num1 + num2;
break;
case "-":
answer = num1 - num2;
break;
case "*":
answer = num1 * num2;
break;
case "/":
answer = num1 / num2;
break;
case "p":
answer = Math.Pow(num1, num2);
break;
default:
answer = 0;
Console.WriteLine("\nSorry, your input wasn't recognised. Please press any key to try again.");
Console.ReadKey();
Environment.Exit(0);
break;
}
Console.WriteLine("\nThe answer to your calculation is: " + answer);
// Wait before ending program
Console.ReadKey();