public
Created

Calculator App Example

  • Download Gist
gistfile1.rb
Ruby
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
begin
 
puts "Add, Subtract, Divide, or Multiply?"
command = gets.chomp
if command == "add"
puts "Type in the first number, press enter, then type the other num."
add1 = gets.chomp
add2 = gets.chomp
puts add1.to_f + add2.to_f
end
if command == "subtract"
puts "Type in the first number, press enter, then type the other num."
sub1 = gets.chomp
sub2 = gets.chomp
puts sub1.to_f - sub2.to_f
end
if command == "divide"
puts "Type in the first number, press enter, then type the other num."
div1 = gets.chomp
div2 = gets.chomp
puts div1.to_f / div2.to_f
end
if command == "multiply"
puts "Type in the first number, press enter, then type the other num."
mult1 = gets.chomp
mult2 = gets.chomp
puts mult1.to_f * mult2.to_f
end
puts "Would you like to calculate again?"
command1 = gets.chomp
end while command1 == "yes"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.