Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SR
- def self.initialize
- $srednia = []
- end
- def self.srednia_wazona(x)
- $result = 0.0
- $sum = 0.0
- x.each{|y|
- $result += ((y[0].to_f)*(y[1].to_f))
- $sum += y[1].to_f
- }
- $result /= $sum
- return $result
- end
- def self.do_nothing
- end
- def self.main_loop
- print "Obliczanie sredniej wazonej\nby Narzew\n"
- loop do
- loop do
- print "Podaj liczbe\n"
- liczba = gets.chomp!.to_i
- print "Podaj mnoznik\n"
- mnoznik = gets.chomp!.to_i
- unless mnoznik == 0
- unless liczba == 0
- $srednia << [liczba, mnoznik]
- else
- print "Podaj poprawne dane!\n"
- end
- else
- print "Podaj poprawne dane!\n"
- end
- print "Nastepna ocena ? [Y/N]\n"
- mode = gets.chomp!
- case mode.to_s
- when "Y"
- SR.do_nothing
- when "y"
- SR.do_nothing
- else
- break
- end
- end
- print "Srednia wazona to #{SR.srednia_wazona($srednia)}\n"
- print "Policzyc kolejna srednia ? [Y/N]\n"
- mode = gets.chomp!
- case mode.to_s
- when "Y"
- SR.do_nothing
- when "y"
- SR.do_nothing
- else
- break
- end
- end
- end
- def self.exit_program
- print "Dziekuje za uruchomienie mojego programu ;)\nCopyright by Narzew\n12.04.2013\nnarzew@gmail.com\n"
- $stdin.gets
- end
- end
- begin
- SR.initialize
- SR.main_loop
- SR.exit_program
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement