Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make a calculator in ruby.
#1
My simple script to make a calculator, made it in less then 7 minutes i believe:
Code:
puts 'please type add for addition, sub for subtraction, div for division, or mult for multiplication.'
#  telling them that they need to do this.
command = gets.chomp
#  this gets the command to tell what type of math they are doing.

if command == 'add'
   puts 'please put the first number in, press enter, then put in the second number, and press enter.'
addone = gets.chomp
addtwo = gets.chomp
puts addone.to_f + addtwo.to_f
end

if command == 'sub'
   puts 'please put the first number in, press enter, then put in the second number, and press enter.'
subone = gets.chomp
subtwo = gets.chomp
puts subone.to_f - subtwo.to_f
end

if command == 'div'
   puts 'please put the first number in, press enter, then put in the second number, and press enter.'
divone = gets.chomp
divtwo = gets.chomp
puts divone.to_f / divtwo.to_f
end

if command == 'mult'
   puts 'please put the first number in, press enter, then put in the second number, and press enter.'
multone = gets.chomp
multtwo = gets.chomp
puts multone.to_f * multtwo.to_f
end
[Image: 728x90_SF.gif]
Reply


Messages In This Thread
How to make a calculator in ruby. - by Soundwave - 01-04-2011, 09:32 PM
RE: How to make a calculator in ruby. - by Break - 01-05-2011, 12:23 PM
RE: How to make a calculator in ruby. - by Boo‌ - 08-03-2011, 02:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting Started With Ruby eax 7 5,031 12-13-2012, 10:03 AM
Last Post: L-Carnitine
  [Tut] How to install Ruby on Mac, Windows and Linux Jordan L. 13 8,447 12-13-2012, 07:49 AM
Last Post: L-Carnitine
  Ruby eBook sockatobi 7 3,068 12-13-2012, 07:48 AM
Last Post: L-Carnitine
  what is ruby on rails DaUB3R 3 2,033 11-01-2012, 04:20 AM
Last Post: johnnymward
  Should I Start Ruby? BreShiE 13 5,772 11-13-2011, 04:14 PM
Last Post: Speedy

Forum Jump:


Users browsing this thread: 1 Guest(s)