Created
January 18, 2014 17:45
-
-
Save trentont101/8493729 to your computer and use it in GitHub Desktop.
A calculator (with feelings)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# METHOD 1 ADDITION (add) | |
def add | |
puts ' ' | |
puts ' ' | |
puts "Please enter your first number" | |
num1 = gets.strip.to_i | |
puts ' ' | |
puts "Please enter your secound number" | |
num2 = gets.strip.to_i | |
num3 = num1 + num2 | |
puts ' ' | |
puts "The product of #{num1} + #{num2} = #{num3}" | |
puts ' ' | |
puts ' ' | |
puts ' ' | |
intro # this sends us back to the intro after calculation | |
end | |
# METHOD 2 SUBTRACT (sub) | |
def sub | |
puts ' ' | |
puts ' ' | |
puts "Please enter your first number" | |
num1 = gets.strip.to_i | |
puts ' ' | |
puts "Please enter your secound number" | |
num2 = gets.strip.to_i | |
puts ' ' | |
num3 = num1 + num2 | |
puts "The product of #{num1} - #{num2} = #{num3}" | |
puts ' ' | |
puts ' ' | |
puts ' ' | |
puts ' ' | |
intro | |
end | |
# METHOD 3 MULTIPLY (mul) | |
def mul | |
puts ' ' | |
puts ' ' | |
puts "Please enter your first number" | |
num1 = gets.strip.to_i | |
puts ' ' | |
puts "Please enter your secound number" | |
num2 = gets.strip.to_i | |
puts ' ' | |
num3 = num1 + num2 | |
puts "The product of #{num1} * #{num2} = #{num3}" | |
puts ' ' | |
puts ' ' | |
puts ' ' | |
intro | |
end | |
# INTRO TO OUR PROGRAM | |
def intro | |
puts "Hello and welcome to your friendly neighborhood calculator" | |
puts " ** YOUR CALCULATOR BOWS LOW BEFORTH YOU ** " | |
puts " Please first give us your method (add, sub, mul) " | |
puts "Sorry im still in 3rd grade and dont know division" | |
puts " ******************* BLUSH **********************" | |
#Which method are we chosing? | |
answer = gets.strip | |
if answer == "add" then add # if answer = add then add method | |
end | |
add = | |
if answer == "sub" then sub # if answer = sub then sub method | |
end | |
if answer == "mul" then mul # if answer = mul then mul method | |
end | |
if answer == "exit" # if answer == exit then end program | |
Kernel::exit | |
end | |
if answer != "add" "sub" "mul""exit" # if answer is not 1 2 3 4 | |
puts "INVALID OPTION" # type this | |
intro | |
end | |
end | |
intro | |
# sorry about the layout (or lack of) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment