-
Notifications
You must be signed in to change notification settings - Fork 0
/
calc.nim
75 lines (49 loc) · 1.79 KB
/
calc.nim
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
import strutils
var userInput: string
var num1: float
var num2: float
var result: float
while true:
echo "Choose your action: Add, Sub, Multiply, Divide, Percentage, Exit (case sensetive)"
userInput = stdin.readLine()
if userInput == "Exit":
break
case userInput:
of "Add":
stdout.write "First Number: "
num1 = stdin.readLine().parseFloat()
stdout.write "Second Number: "
num2 = stdin.readLine().parseFloat()
result = num1 + num2
stdout.writeLine "Result: ", result
of "Sub":
stdout.write "First Number: "
num1 = stdin.readLine().parseFloat()
stdout.write "Second Number: "
num2 = stdin.readLine().parseFloat()
result = num1 - num2
stdout.writeLine "Result: ", result
of "Multiply":
stdout.write "First Number: "
num1 = stdin.readLine().parseFloat()
stdout.write "Second Number: "
num2 = stdin.readLine().parseFloat()
result = num1 * num2
stdout.writeLine "Result: ", result
of "Divide":
stdout.write "First Number: "
num1 = stdin.readLine().parseFloat()
stdout.write "Second Number: "
num2 = stdin.readLine().parseFloat()
result = num1 / num2
stdout.writeLine "Result: ", result
of "Percentage":
stdout.writeLine "Enter %: "
num1 = stdin.readLine.parseFloat()
stdout.writeLine "Enter Total: "
num2 = stdin.readLine.parseFloat()
result = (num1 / 100) * num2
stdout.writeLine "The result is: " , result
# to break the program we can also do
#[ of "Exit":
break ]#