Created
January 19, 2013 01:30
-
-
Save rvictory/4570115 to your computer and use it in GitHub Desktop.
Calculator App Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment