Support Forums

Full Version: How to make a calculator in ruby.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
Thanks im going to try this right now Smile
(01-05-2011, 12:23 PM)Break Wrote: [ -> ]Thanks im going to try this right now Smile

Good luck on that.
Hmmm, nice. Thanks for sharing.
(01-06-2011, 04:43 AM)T3RRi8Le™ Wrote: [ -> ]Hmmm, nice. Thanks for sharing.

No problem, Ruby is my favorite and only language right now.
thanks, will help me expand my knowledge
(01-31-2011, 07:53 PM)bigandrewgold Wrote: [ -> ]thanks, will help me expand my knowledge

No problem, glad I can help.
Never really got into ruby but I'll give it a try I guess. Big Grin
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?
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.
Pages: 1 2