tui_calc.rb
# TUI for when calculator is run from command line
# accepts an optional command line argument -v for verbose output
TUI for when calculator is run from command line
accepts an optional command line argument -v for verbose output
TUI for when calculator is run from command line accepts an optional command line argument - v for verbose output
def main
  verbose = false
  if ARGV[0] != nil and ARGV[0].downcase == "-v"
    verbose = true
  end
  puts "Instructions: enter a mathematical expression using +, -, *, /, **, or (q)uit"
  puts "Calculator follows order of operations"
  puts "All elements must be separated by spaces"
  puts "e.g. ( 4 + 5 ) * 6"
  print "Enter an expression: "
  expr = STDIN.gets.strip
  until expr.downcase.start_with?("q")
    result = calc(expr, verbose)
    if result == nil
      puts "Please enter a valid expression"
      puts "Common error: all elements should be separated by spaces"
    elsif result % 1 == 0  
      puts result.to_i
    else
      puts result
    end
   print "enter another expression, or (q)uit: "
   expr = STDIN.gets.strip
  end
end
def main verbose = false if ARGV [ 0 ] != nil and ARGV [ 0 ] . downcase == "-v" verbose = true end puts "Instructions: enter a mathematical expression using +, -, *, /, **, or (q)uit" puts "Calculator follows order of operations" puts "All elements must be separated by spaces" puts "e.g. ( 4 + 5 ) * 6" print "Enter an expression: " expr = STDIN . gets . strip until expr . downcase . start_with? ( "q" ) result = calc ( expr , verbose ) if result == nil puts "Please enter a valid expression" puts "Common error: all elements should be separated by spaces" elsif result % 1 == 0 puts result . to_i else puts result end print "enter another expression, or (q)uit: " expr = STDIN . gets . strip end end
TUI for when calculator is run from command line
accepts an optional command line argument -v for verbose output
TUI for when calculator is run from command line accepts an optional command line argument - v for verbose output
# determine whether to use verbose outpuut # get input # continue calculating expressions until user quits # send to calc() and print result # print int if result is integer