-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
60 lines (55 loc) · 1.76 KB
/
main.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
58
59
60
puts "What would you like to do?"
puts "Use Basic Calculator(bc), Use Advanced Calculator(ac), Quit(q)?"
you = gets.chomp.downcase
def advcalc
print "Welcome to the Advanced Calculator. Would you like to take an nth (p)ower or the square (r)oot? "
answer = gets.chomp
if answer == "p"
puts "Let's take the nth power of a number."
print "Please enter your number "
number = gets.chomp.to_i
print "Please enter your power "
power = gets.chomp.to_i
puts "The answer is #{number**power}."
elsif answer == "r"
puts "Let's take the square root of a number."
print "Please enter your number "
number = gets.chomp.to_i
puts "The answer is #{number**(1.0/2)}."
else
puts 'Error. Please enter "p" "pr" "r" to run the use the advanced calculator.'
end
end
def basic_calc
# User chooses math action and enters their numbers
print "Would you like to add, subtract, multiply, or divide? "
math_action = gets.chomp
print "Please enter your first number: "
first_number = gets.chomp.to_i
print "Please enter your second number: "
second_number = gets.chomp.to_i
#This is where the numbers have math actions done against them
case math_action
when "add"
puts "The answer is #{first_number + second_number}"
when "subtract"
puts "The answer is #{first_number - second_number}"
when "multiply"
puts "The answer is #{first_number * second_number}"
when "divide"
puts "The answer is #{first_number / second_number}"
else
print "error"
end
end
while you != "q"
if you == "bc"
basic_calc
elsif you == "ac"
advcalc
end
puts "What would you like to do?"
puts "Use Basic Calculator(bc), Use Advanced Calculator(ac), Quit(q)?"
you = gets.chomp.downcase
end
puts "Thank you"