Quiz: Restocking
The function restock should add amount to every item in the shop. But the program prints bread: 2 and potion: 0, as if the function did nothing. Click the line with the mistake.
1#include <iostream>
2#include <map>
3#include <string>
4
5void restock(std::map<std::string, int>& shop, int amount) {
6 for (auto [item, count] : shop) {
7 count += amount;
8 }
9}
10
11int main() {
12 std::map<std::string, int> shop = {{"bread", 2}, {"potion", 0}};
13 restock(shop, 5);
14
15 for (const auto& [item, count] : shop) {
16 std::cout << item << ": " << count << std::endl;
17 }
18 return 0;
19}