This repository has been archived by the owner on Dec 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleCalculator.cs
78 lines (68 loc) · 2.33 KB
/
SimpleCalculator.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Simple calculator made by Sh0w3D # Kamil Oberaj
// Created in .NET 5.0
using System;
namespace SimpleCalculator
{
class Program
{
static void displayOptions()
{
Console.WriteLine("There are available options:");
Console.WriteLine(new string(' ', 2) + "1 > Add");
Console.WriteLine(new string(' ', 2) + "2 > Subtract");
Console.WriteLine(new string(' ', 2) + "3 > Multiply");
Console.WriteLine(new string(' ', 2) + "4 > Divide");
Console.WriteLine(new string(' ', 2) + "e > Exit");
Console.Write("Choose one: ");
}
static double makeCalculations(string symbol, double x, double y)
{
double result = double.NaN;
switch (symbol)
{
case "1":
result = x + y;
break;
case "2":
result = x - y;
break;
case "3":
result = x * y;
break;
case "4":
if(x == 0.0 || y == 0.0)
{
Console.WriteLine("Error, you can't divide by 0!");
result = 0;
break;
} else
{
result = x / y;
break;
}
default:
Environment.Exit(0);
break;
}
return result;
}
static void Main(string[] args)
{
displayOptions();
double firstNumber, secondNumber, finish;
string chosenOption = Console.ReadLine();
if(chosenOption == "e")
{
Environment.Exit(0);
}
Console.Clear();
Console.WriteLine("Your option: " + chosenOption);
Console.Write("Please input first number: ");
firstNumber = Convert.ToDouble(Console.ReadLine());
Console.Write("Please input second number: ");
secondNumber = Convert.ToDouble(Console.ReadLine());
finish = makeCalculations(chosenOption, firstNumber, secondNumber);
Console.WriteLine("Your calculations: " + finish);
}
}
}