Created
March 27, 2020 20:21
-
-
Save AdryDev92/d61bd0fa3b620e4ef494563b33294b57 to your computer and use it in GitHub Desktop.
Basic calculator in ruby with four operations. If you press "N" after an operation, the app ends.
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
puts "======================" | |
puts "| CALCULADORA BÁSICA |" | |
puts "| EN RUBY |" | |
puts "======================" | |
ops = ["1.suma","2.resta","3.multiplicación","4.división"] | |
begin | |
puts "\n¿Qué operación deseas realizar?" | |
puts ops[0] | |
puts ops[1] | |
puts ops[2] | |
puts ops[3] | |
op1 = gets.chomp.to_i | |
if op1 == 1 | |
puts "Introduce los números a sumar:" | |
sum1 = gets.chomp.to_i | |
sum2 = gets.chomp.to_i | |
res = sum1 + sum2 | |
puts "\nEl resultado de sumar (#{sum1} + #{sum2}) es: #{res}" | |
elsif op1 == 2 | |
puts "Introduce los números a restar:" | |
res1 = gets.chomp.to_i | |
res2 = gets.chomp.to_i | |
res = res1 - res2 | |
puts "\nEl resultado de restar (#{res1} - #{res2}) es: #{res}" | |
elsif op1 == 3 | |
puts "Introduce los números a multiplicar:" | |
mul1 = gets.chomp.to_i | |
mul2 = gets.chomp.to_i | |
res = mul1 * mul2 | |
puts "\nEl resultado de multiplicar (#{mul1} * #{mul2}) es: #{res}" | |
elsif op1 == 4 | |
puts "Introduce los números a dividir:" | |
div1 = gets.chomp.to_i | |
div2 = gets.chomp.to_i | |
res = div1 / div2 | |
puts "\nEl resultado de dividir (#{div1} / #{div2}) es: #{res}" | |
end | |
puts "\n¿Deseas realizar una nueva operación?\nS/N" | |
respuesta = gets.chomp | |
end while (respuesta == "s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment