Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions calculator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# ruby calculator

#operator
puts "Welcome to the Calculator program! Which operator would you like to use?
1. add(+)
2. subtract(-)
3. multiply (*)
4. divide(/)
Please choose one operator (name or symbol): "
math_operator = gets.chomp


#number 1
puts "Choose the first number for the math operation: "
num_one = gets.chomp.to_i


# number 2
puts "Choose the second number for the math operation: "
num_two = gets.chomp.to_i

until ["add", "+", "subtract", "-", "multiply", "*", "divide", "/"].include?(math_operator)
puts "Please tell me to add (+), subtract (-), multiply (*), or divide (/)!"
math_operator = gets.chomp
end


case math_operator
when "add", "+"
puts num_one + num_two
when "subtract", "-"
puts num_one - num_two
when "multiply", "*"
puts num_one * num_two
when "divide", "/"
puts num_one / num_two
end