Support Forums
How to make a calculator in ruby. - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Ruby and Ruby on Rails (https://www.supportforums.net/forumdisplay.php?fid=55)
+---- Thread: How to make a calculator in ruby. (/showthread.php?tid=15345)

Pages: 1 2


How to make a calculator in ruby. - Soundwave - 01-04-2011

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



RE: How to make a calculator in ruby. - Break - 01-05-2011

Thanks im going to try this right now Smile


RE: How to make a calculator in ruby. - Soundwave - 01-05-2011

(01-05-2011, 12:23 PM)Break Wrote: Thanks im going to try this right now Smile

Good luck on that.


RE: How to make a calculator in ruby. - T3RRi8Le™ - 01-06-2011

Hmmm, nice. Thanks for sharing.


RE: How to make a calculator in ruby. - Soundwave - 01-06-2011

(01-06-2011, 04:43 AM)T3RRi8Le™ Wrote: Hmmm, nice. Thanks for sharing.

No problem, Ruby is my favorite and only language right now.


RE: How to make a calculator in ruby. - Bigandrewgold - 01-31-2011

thanks, will help me expand my knowledge


RE: How to make a calculator in ruby. - Soundwave - 01-31-2011

(01-31-2011, 07:53 PM)bigandrewgold Wrote: thanks, will help me expand my knowledge

No problem, glad I can help.


RE: How to make a calculator in ruby. - Trustable - 07-30-2011

Never really got into ruby but I'll give it a try I guess. Big Grin


RE: How to make a calculator in ruby. - BreShiE - 07-30-2011

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?


RE: How to make a calculator in ruby. - Deceive - 08-03-2011

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.