[Ruby] Multi-use Calculator 04-05-2015, 04:17 PM
#1
I woke up yesterday and said "Fuck it. I'm making a calculator." So I did.
Currently, I have a reference sheet (perfect squares, perfect cubes and prime numbers), a basic calculator and a more advanced calculator.
I have plans to make a trig/calculus calculator but I suck at both of them so I need a bit of help for that.
I also have plans for geometry references and formulas.
Anyway, enjoy!
Currently, I have a reference sheet (perfect squares, perfect cubes and prime numbers), a basic calculator and a more advanced calculator.
I have plans to make a trig/calculus calculator but I suck at both of them so I need a bit of help for that.
I also have plans for geometry references and formulas.
Anyway, enjoy!
Code:
#SciCalc by Nightc||ed, ©2015
@pi = Math::PI
@e = Math::E
def dir
def get_int_values_a
[gets, gets].map{ |s| s.chomp.to_i }
end
def get_int_values_b
[gets].map{ |s| s.chomp.to_i }
end
system "cls"
puts """ Directory
[1] References
[2] Basic calculator
[3] Advanced calculator
[4] Trig/Calc"""
sect = gets.chomp
system "cls"
case sect
when "1"
puts """ References
[to go back to the directory, hit enter]
Pi: #{@pi}
e: #{@e}
Perfect squares, to 12x:
1, 4, 9, 16, 25, 36, 49,
64, 81, 100, 121, 144
Perfect cubes, to 12x:
1, 8, 27, 64, 125, 216,
343, 512, 729, 1000,
1331, 1728
Prime numbers, to 100:
1, 2, 3, 5, 7, 11, 13,
17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61,
67, 71, 73, 79, 83, 89,
97
"""
when "2"
puts "Would you like to [1]add, [2]multiply, [3]subtract or [4]divide?"
response = gets.chomp
system "cls"
case response
when "1"
puts "Which numbers would you like to add (first value, enter, second value)?"
operator = :+
when "2"
puts "Which numbers would you like to subtract (first value, enter, second value)?"
operator = :-
when "3"
puts "Which numbers would you like to multiply (first value, enter, second value)?"
operator = :*
when "4"
puts "Which numbers would you like to divide (first value, enter, second value)?"
operator = :/
end
answer = get_int_values_a.inject(operator)
puts "The answer is... #{answer}"
when "3"
puts "would you like to use [1]modulus, [2]exponent, [3]square root or [4]cube root?"
response = gets.chomp
system "cls"
case response
when "1"
puts "Which numbers would you like to use (first value, enter, second value)?" #if anyone knows the use term for modulus, lmk
operator = :%
answer = get_int_values_a.inject(operator)
puts "The answer is... #{answer}"
when "2"
puts "Which numbers would you like to use (first value, enter, second value)?"
operator = :**
answer = get_int_values_a.inject(operator)
puts "The answer is... #{answer}"
when "3"
puts "What number would you like to root?"
a = gets.to_i
a = Math.sqrt(a)
puts "The answer is... #{a}"
when "4"
puts "What number would you like to root?"
a = gets.to_i
a = (Math.exp(Math.log(a.to_i)/3.to_i)).round
puts "The answer is... #{a}"
end
when "4"
puts "WIP"
end
kden = gets.chomp
dir
end
dirIt's often the outcasts, the iconoclasts ... those who have the least to lose because they
don't have much in the first place, who feel the new currents and ride them the farthest.
don't have much in the first place, who feel the new currents and ride them the farthest.















![[+]](https://sinister.ly/images/modern/collapse_collapsed.png)





