Advertisement
Hiteshw11

Simple Calculator in Ruby

Sep 27th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.69 KB | None | 0 0
  1. puts "Enter the first number"
  2. first=gets.chomp().to_f
  3. puts "Enter the second number"
  4. second=gets.chomp().to_f
  5. op=""
  6. while (op!=5)
  7.  puts "Enter the operation you wish to perform"
  8.  puts "1.Addition\n2.Subtraction\n3.Multiplication\n4.Division\n5.Exit"
  9.  op=gets.chomp()
  10.  if op=="1"
  11.    sum=first+second
  12.    puts "The addition of two numbers is "+sum.to_s
  13.  elsif op=="2"
  14.    sub=first-second
  15.    puts "The subtraction of two numbers is "+sub.to_s
  16.  elsif op=="3"
  17.    mul=first*second
  18.    puts "The multiplication of two numbers is "+mul.to_s
  19.  elsif op=="4"
  20.    div=first/second
  21.    puts "The division of two numbers is "+div.to_s
  22.  elsif op=="5"
  23.    exit
  24.  else
  25.    puts "Invalid Selection"
  26.  end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement