Witam wszystkich! Mam pytanie.. czy wie ktoś, jak wykonać takie zadanie (w Ruby)?
A. Using files, make a program that can keep track of how much an individual consumes at the Friday Bar. IE: Morten had 15 tequila shots.
B. It should separate between soft drinks, beer and drinks.
UTKNĘŁAM W TYM MOMENCIE
require 'IO/console'
file = File.new("tab.txt", "w")
class Tab
def inputBeer
file = File.new("tab.txt", "a")
file.puts("b")
file.close
end
def inputSoftdrink
file = File.new("tab.txt", "a")
file.puts("s")
file.close
end
def inputDrink
file = File.new("tab.txt", "a")
file.puts("d")
file.close
end
def prinTab
file = File.new("tab.txt", "r")
@beer = File.read("tab.txt").count('b')
@softdrink = File.read("tab.txt").count('s')
@drink = File.read("tab.txt"). count('d')
print "BEERS = #{@beer}; SOFTDRINKS = #{@softdrink}; DRINKS = #{@drink}\r"
file.close
end
end
tab = Tab.new
puts "1 = ADD BEER\n2 = ADD SOFT DRINK\n3 = ADD DRINK\n4 = EXIT"
input = STDIN.getch.to_i
while (input != 4)
if (input == 0)
input = STDIN.getch.to_i
elsif (input == 1)
tab.inputBeer
tab.prinTab
input = 0
elsif (input == 2)
tab.inputSoftdrink
tab.prinTab
input = 0
elsif (input == 3)
tab.inputDrink
tab.prinTab
input = 0
else
input = 0
end
end