Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(car).
- -export([listPrices/1]).
- listPrices(Currency) ->
- Cars = ["BMW i8", "Laborghini Huracan", "Ferrari f12"],
- Prices = #{"BMW i8" => 150000, "Laborghini Huracan" => 500000, "Ferrari f12" => 700000},
- case Currency of
- eur -> printCars(Cars, Prices, 0.86, Currency);
- gbp -> printCars(Cars, Prices, 0.77, Currency);
- usd -> printCars(Cars, Prices, 1, Currency)
- end.
- printCars([], Prices, CurrencyRate, Currency) ->
- Currency;
- printCars([FirstCar | Rest], Prices, CurrencyRate, Currency) ->
- printCurrency({FirstCar, maps:get(FirstCar, Prices, -1) * CurrencyRate, Currency}),
- printCars(Rest, Prices, CurrencyRate, Currency).
- printCurrency({Car, Price, Currency}) ->
- io:fwrite(Car ++ ": " ++ integer_to_list(round(Price)) ++ "\n").
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement