-2

I just wanted to work on one method then replicate it to the rest. which is why one method is really only done. (kinda)

puts "Welcome to My Calculator! "  

print "Please place in the numbers. "  

first_number = gets.to_i  

print "Second number. "  

second_number = gets.to_i  


puts "What operation? "  

operation_selection = gets  

if(operation_selection == "add")  

  addition_function  

  puts"#{result}"

end  


def addition_function
 result = first_number + second_number

end

def subtraction_function
  result = first_number - second_number

end

def divison_function
   result = first_number / second_number

end

def multiplication_function
  result = first_number * second_number

end
Enamul Hassan
  • 5,266
  • 23
  • 39
  • 56
Clueless
  • 13
  • 2
  • 1
    If after solving for this for me if you could find a way to make it not look so crude and repetitive, thanks. – Clueless Jun 15 '16 at 00:16
  • I would really advise following a tutorial on how to get started, a similar post can be found at http://stackoverflow.com/questions/20850598/programming-a-basic-calculator-in-ruby – Nabeel Jun 15 '16 at 00:42
  • This seems not that far off. Try using `gets.chomp` instead of just `gets`. – max pleaner Jun 15 '16 at 01:44

1 Answers1

0

Is this what you want?

puts "Welcome to My Calculator! "  

print "Please place in the numbers. "  

first_number = gets.to_i  

print "Second number. "  

second_number = gets.to_i  


puts "What operation? "  

operation_selection = gets.chomp.downcase.to_s  

def oper(operation_sel, first_number,second_number)
    case operation_sel
        when "add"
            puts first_number + second_number
        when "sub"
            puts first_number - second_number
        when "div"
            puts first_number / second_number
        when "mul"
            puts first_number * second_number
        end
end

oper(operation_selection,first_number,second_number)
kenshinji
  • 2,021
  • 4
  • 25
  • 39
  • Yeah this is what I was looking for. I completely passed over the case option but I'm still wondering why my if statement didn't go through if you could answer that. – Clueless Jun 15 '16 at 02:32
  • @Clueless I think that's why you should use `gets.chomp` instead of `gets`, and you can check the answer from [here](http://stackoverflow.com/questions/22166108/difference-between-gets-gets-chomp-and-gets-chomp) – kenshinji Jun 15 '16 at 02:43