0

Hey Guys, Help Please (Ruby Basics)

So i wanted to build a calculator and hit a dead end think any of u can help?? My Code: def addition_function puts "Which numbers would you like to add?" @n1 = gets.chomp.to_i @n2 = gets.chomp.to_i @answer = @n1 + @n2 puts "The sum is... #{@answer}" end def subtraction_function puts "Which numbers would you like to subtract?" @n1 = gets.chomp.to_i @n2 = gets.chomp.to_i @answer = @n1 - @n2 puts "The answer is... #{@answer}" end def multiplication_function puts "Which numbers would you like to multiply?" @n1 = gets.chomp.to_i @n2 = gets.chomp.to_i @answer = @n1 * @n2 puts "The answer is... #{@answer}" end response = gets.chomp.to_i if response == "add" then addition_function end if response == "subtract" then subtraction_function end if response == "multiply" then multiplication_function end

4th Jan 2022, 1:49 PM
Jorden Coutinho
Jorden Coutinho - avatar
2 Respuestas