Created a simple calculator

project
ruby

#1

I created another simple program (see the topics I posted for the other things I made).

Running out of ideas on what to do. Like simple stuff what to do.

I already made a LogIn System and a Random Word Generator and now a Calculator. So what is next?

Anyone have any challanges for me?

Here is the code.

def magic(o,n1,n2)
   
    if o == "*"
        return n1 * n2
    elsif o == "+"
        return n1 + n2
    elsif o == "/"
        return n1 / n2
    elsif o == "-"
        return n1 - n2
end
        
end


puts "////////////////////////////////"
puts "// Welcome to the calculator! //"
puts "////////////////////////////////"


puts ""
puts ""

puts "Well I suck at coding so this will be a really stupid calculator."
puts "So put in a number and then put in +, *, -, or /."
puts "If you don't know what does what then don't use this."

puts "So first things first, we need a number:"
num1 = Integer(gets.chomp)
puts "Now what do you what to do with it, multiply, add, subtract or divide?(+, -, *, /)"
oo = gets.chomp

unless oo == "-" or oo == "+" or oo == "*" or oo == "/"
puts "Error: Incorrect input, please try again!"
oo = gets.chomp
end

puts "Now we need another number:"
num2 = Integer(gets.chomp)


sum = magic(oo,num1,num2)

puts "If you want to continue adding, subtracting, dividing and multiplying then type in 'go' and press enter to continue. If you want to see the sum of all numbers just type in '=' !"
answer = gets.chomp

until answer == "="

puts "Now do you want to add, subtract, divide, multiply or see the combination of those numbers? (*, +, /, -, =)"
answer = gets.chomp

break if answer == "="

puts ""
puts "Now pick a number:"
num2 = Integer(gets.chomp)

sum = magic(answer,sum,num2)

end

if answer == "="
    puts "The whole combo of those numbers ended up being #{sum}!"
end

puts "Created By"

puts ""

puts"   ___  _  __     __ "
puts"  / _ \/ |/ /_ __/ /_"
puts" / ___/    / // / __/"
puts"/_/  /_/|_/\_,_/\__/"
puts "PNut"

#2

Just a challenge if you are up to it, can you make a dice? Good luck haha! Awesome job on this one


#3

use the math module to add more functionality for your calculator, you'll probably learn a thing or two.