Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Stacks_Olivia_Calculator_.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
puts "Let's do some math. What kind of math should we do?"

operator = gets.chomp
until ["add", "+", "addition", "plus", "subtract", "subtraction", "-", "multiply", "*", "times", "multiplication", "division", "/", "divide"].include?(operator)
puts "Uh, yeah. Right. Also, please tell me to add (+), subtract (-)!, multiply, divide, etc..."
operator = gets.chomp
end

puts "Good job. Enter a number."
num1 = gets.chomp.to_f
https://github.com/Ada-C7/ride-share
until num1 =~ /\A[+-]?\d+(\.[\d]+)?\z/.match(num1)
puts "Please enter a JUST A NUMBER, Shakespeare."
end

puts "We'll need one more number to do stuff."
num2 = gets.chomp.to_f
until num2 =~ /\A[+-]?\d+(\.[\d]+)?\z/.match(num2)
puts "You have terrible short-term memory. Sorry. JUST A NUMBER."
end

def calculate(num1, num2, operator)
case operator
when "add", "+", "addition", "plus"
puts (num1 + num2)
when "minus", + "-", "subtraction"
puts (num1 - num2)
when "multiply", "*", "times", "multiplication"
puts (num1 * num2)
when "division", "/", "divide"
puts (num1 / num2)
else puts "Whatevuh. What even is that?"
end
end

calculate(num1, num2, operator)

96 changes: 96 additions & 0 deletions Stacks_Olivia_Calculator_Sunday.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@

puts "Let's do some math. What kind of math should we do?"

operator = gets.chomp

until ["+", "-", "*", "/"].include?(operator)
puts "Neato, but please tell me to (+), (-), (*), (/)."
operator = gets.chomp
end

puts "Good job. Now enter a number."
num1 = gets.chomp

unless num1.match(/\d(?![a-zA-Z])/)
puts "Please just enter a digit, Shakespeare."
else
puts "We'll need one more number to do stuff."
#num1.match(/\d(?![a-zA-Z])/) == nil
end

#while num1.match(/\d(?![a-zA-Z])/) == nil

num2 = gets.chomp

unless num2.match(/\d(?![a-zA-Z])/)
puts "You have terrible short-term memory. Sorry. Just enter a number."
#num2 = gets.chomp
else #num2.match(/\d(?![a-zA-Z])/) == true
puts "...Let's do the math..."
end


def calculate(num1, num2, operator)
num1 = num1.to_i.to_f
num2 = num2.to_i.to_f
case operator
when "+"
puts (num1 + num2)
when "-"
puts (num1 - num2)
when "*"
puts (num1 * num2)
when "/"
puts (num1 / num2)
end
end
puts "#{num1}#{operator}#{num2} "
calculate(num1, num2, operator)



#things I tried that didn't work well or at all:

#def alpha_check_loop(input)
#alpha_check_loop(num1)
# puts "We'll need one more number to do stuff."
# num2 = gets chomp
# alpha_check_loop(num1)

#regexs i tried: `num1 =~ /\A[+-]?\d+(\.[\d]+)?\z/.match(num1)`
# `num2 =~ /\A[+-]?\d+(\.[\d]+)?\z/.match(num2)``

# until num1.match(/\d(?![a-zA-Z])/)
# puts "Please enter a just a number, Shakespeare."
# if num1.match(/\d(?![a-zA-Z])/)
# puts "Great. We'll need one more number to do stuff."
# num1 = num1.to_i
# end
# end
# num2 = gets.chomp
# until num2.match(/\d(?![a-zA-Z])/)
# puts "You have terrible short-term memory. Sorry. Just enter a number."
# if num2.match(/\d(?![a-zA-Z])/)
# puts "...Let's do the math..."
# num2 = num2.to_i
# end
# end

#if num1 == "0"
# def numeric?(num1)
# Float(self) != nil rescue false
# end
# def number?(num1)
# num1 = num1.to_s unless obj.is_a? String
# /\A[+-]?\d+(\.[\d]+)?\z/.match(obj)
# end
# #=~ /\A[+-]?\d+(\.[\d]+)?\z/

# def letter?(input)
# num1 =~ /[[:alpha:]]/
#
# end
#
# def numeric?(lookAhead)
# lookAhead =~ /[[:digit:]]/
#end