Skip to content

Instantly share code, notes, and snippets.

@Kiandisor
Created June 23, 2021 12:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiandisor/0d6ff8532e1a09e2623d5f2181b58fda to your computer and use it in GitHub Desktop.
Save Kiandisor/0d6ff8532e1a09e2623d5f2181b58fda to your computer and use it in GitHub Desktop.
[2021-06-07] Challenge #393 [Easy] Making change - C++ 20 Solution
[[nodiscard]] /*constexpr*/ int make_change(int current_money) {
int change_amount {0};
auto generate_change {[&current_money,&change_amount](int bill_size) {
change_amount += current_money/bill_size;
current_money %= bill_size;
}};
std::ranges::for_each(std::array {500,100,25,10,5,1},generate_change);
return change_amount+=current_money;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment