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
42 changes: 42 additions & 0 deletions wk1_calc.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#Calculator Exercise
#command line interface that allows a user to perform simple arithmetic

puts "This calculator will perform simple arithmetic on two numbers, using either addition, subtraction, multiplication, or division."
puts

print "What is the first number? "
num_one = gets.chomp.to_f

print "What is the second number? "
num_two = gets.chomp.to_f

print "Which operation would you like performed? "
command = gets.chomp.upcase.to_s

until ["ADD", "+", "SUBTRACT", "-", "MULTIPLY", "*", "DIVIDE", "/"].include?(command)
puts "You did not enter an available operation. Please try again."
command = gets.chomp.upcase.to_s
end

puts command

case command
when "ADD", "+"
puts "We're adding numbers"
puts num_one + num_two
when "SUBTRACT", "-"
puts "We're subtracting numbers"
puts num_one - num_two
when "MULTIPLY", "*"
puts "We're multiplying numbers"
puts num_one * num_two
when "DIVIDE", "/"
puts "We're dividing numbers"
puts num_one / num_two
else
puts "You did not enter an available operation. Please try again."
end


#Bike rack for future enhancements
#av_commands = ["ADD", "+", "SUBTRACT", "-", "MULTIPLY", "*", "DIVIDE", "/"]