Advertisement
ingenmaffen

car.erl

Oct 10th, 2019
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.80 KB | None | 0 0
  1. -module(car).
  2.  
  3. -export([listPrices/1]).
  4.  
  5. listPrices(Currency) ->
  6.     Cars = ["BMW i8", "Laborghini Huracan", "Ferrari f12"],
  7.     Prices = #{"BMW i8" => 150000, "Laborghini Huracan" => 500000, "Ferrari f12" => 700000},
  8.     case Currency of
  9.         eur -> printCars(Cars, Prices, 0.86, Currency);
  10.         gbp -> printCars(Cars, Prices, 0.77, Currency);
  11.         usd -> printCars(Cars, Prices, 1, Currency)
  12.     end.
  13.  
  14. printCars([], Prices, CurrencyRate, Currency) ->
  15.         Currency;
  16. printCars([FirstCar | Rest], Prices, CurrencyRate, Currency) ->
  17.     printCurrency({FirstCar, maps:get(FirstCar, Prices, -1) * CurrencyRate, Currency}),
  18.     printCars(Rest, Prices, CurrencyRate, Currency).
  19.  
  20.  
  21. printCurrency({Car, Price, Currency}) ->
  22.     io:fwrite(Car ++ ": " ++ integer_to_list(round(Price)) ++ "\n").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement