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
#2
Thanks im going to try this right now Smile
[Image: breaky.png]
Reply
#3
(01-05-2011, 12:23 PM)Break Wrote: Thanks im going to try this right now Smile

Good luck on that.
[Image: 728x90_SF.gif]
Reply
#4
Hmmm, nice. Thanks for sharing.
Reply
#5
(01-06-2011, 04:43 AM)T3RRi8Le™ Wrote: Hmmm, nice. Thanks for sharing.

No problem, Ruby is my favorite and only language right now.
[Image: 728x90_SF.gif]
Reply
#6
thanks, will help me expand my knowledge
Reply
#7
(01-31-2011, 07:53 PM)bigandrewgold Wrote: thanks, will help me expand my knowledge

No problem, glad I can help.
[Image: 728x90_SF.gif]
Reply
#8
Never really got into ruby but I'll give it a try I guess. Big Grin
Reply
#9
Ruby reminds me of Perl, it uses command line in order to work it. I was thinking about learning it, but I don't know. Slat is it easy or hard to learn?
Reply
#10
You should make one in vb next Smile
I'd love to use this, also a stop watch and count down timer wouldn't be bad either considering I make pizza a lot (Off topic).
But yeah, nice code there, can tell it's not messy.
Legitimate Marketer | Exchanger | Middle Man | RAT Expert
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)