ingenmaffen

car.erl

Oct 10th, 2019
753
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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").
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×