Created
November 25, 2012 10:03
-
-
Save Inza/4142966 to your computer and use it in GitHub Desktop.
Homework PES - T
This file contains 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
# Funkce | |
def print_menu options | |
options.each_with_index do |x, i| | |
puts "#{i+1}: #{x}" | |
end | |
puts 'Dej sem moznost:' | |
end | |
def spocitej a, b, c, op, historie | |
s = "#{a} #{op} #{b} = #{c}" | |
puts s | |
historie << s | |
c | |
end | |
# Konfigurace | |
options = ['+', '-', '*', '/', 'Vymazat Mezivysledek', 'Zobrazit Historii', 'Vymazat Historii', 'Konec'] | |
historie = [] | |
# Program | |
puts 'Dej sem cislo:' | |
a = gets.to_f | |
begin | |
puts "Mezivysledek: #{a}" | |
print_menu options | |
op = gets.to_i | |
puts "Vybral jsi \"#{options[op-1]}\":" | |
if (op >= 1) and (op <= 4) | |
puts 'Dej sem cislo:' | |
b = gets.to_f | |
end | |
case op.to_s | |
when '1' | |
c = a + b | |
a = spocitej a, b, c, options[op-1], historie | |
when '2' | |
c = a - b | |
a = spocitej a, b, c, options[op-1], historie | |
when '5' | |
a = 0 | |
when '6' | |
historie.each_with_index { |e, i| puts "#{i+1}. #{e}" } | |
when '7' | |
historie.clear | |
when '8' | |
# noop | |
else | |
puts "Neznama operace \"#{op}\"" | |
end | |
end while op != 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment