Last active
October 23, 2017 11:16
-
-
Save Papillard/b0bb4b65fbe805cff5c6f56178ff77cb to your computer and use it in GitHub Desktop.
Calculator - Reboot batch #100
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
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 |
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
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