Skip to content

Instantly share code, notes, and snippets.

@Papillard
Last active October 23, 2017 11:16
Show Gist options
  • Save Papillard/b0bb4b65fbe805cff5c6f56178ff77cb to your computer and use it in GitHub Desktop.
Save Papillard/b0bb4b65fbe805cff5c6f56178ff77cb to your computer and use it in GitHub Desktop.
Calculator - Reboot batch #100
def calculate(first, second, operation)
if operation == "+"
result = first + second
elsif operation == "-"
result = first - second
elsif operation == "*"
result = first * second
elsif operation == "/"
result = first / second
else
result = nil
end
return result
end
require_relative "calculator"
choice = "y"
while choice == "y"
print "Entrez le premier chiffre de votre opération > "
first_number = gets.chomp.to_f
print "Entrez le second chiffre de votre opération > "
second_number = gets.chomp.to_f
print "Entrez le type d'opération souhaité (+, -, /, *) > "
operation = gets.chomp
result = calculate(first_number, second_number, operation)
if result
puts "Votre resultat est #{result}"
else
puts "resultat invalide."
end
puts "Veux tu continuer? (y/n)"
choice = gets.chomp
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment