-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.rb
62 lines (35 loc) · 1.14 KB
/
calc.rb
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
puts "Would you like to perform some calculating operations? Type 'yes' or 'no'"
answer = gets.chomp
while answer == 'yes'
puts "Please enter your first number"
num_1 = gets.chomp.to_i
puts "Please enter your second number"
num_2 = gets.chomp.to_i
puts "Please enter '+', '-', '*', '/', '**', 'sin', 'cos', 'tan'"
operator = gets.chomp
if operator == '+'
puts num_1 + num_2
elsif operator == '-'
puts num_1 - num_2
elsif operator == '*'
puts num_1 * num_2
elsif operator == '/'
puts num_1 / num_2
elsif operator == '**'
puts num_1 ** num_2
elsif operator == 'sin'
puts "The sine of the first number is " + Math.asin(num_1).to_s
puts "The sine of the second number is " + Math.asin(num_2).to_s
elsif operator == 'cos'
puts "The cosine of the first number is " + Math.acos(num_1).to_s
puts "The cosine of the second number is " + Math.acos(num_2).to_s
elsif operator == 'tan'
puts "The tangent of your two numbers is " + Math.atan2(num_1, num_2).to_s
else
puts "Please enter valid info!"
end
puts "Would you like to perform some calculating operations? Type 'yes' or 'no'"
answer = gets.chomp
if answer == 'no'
end
end