#include <iostream>
#include <map>
#include <string>

int main()
{
	enum Currency{ Silver = 10, Gold = 50, Silver10oz = 100, Gold10oz = 500 };
	std::map<std::string, unsigned> weapons
	{
		{"M240", 1250u},
		{"M249", 3150u}
	};
	
	std::cout << "Weapons:" << std::endl;
	for(auto const &it: weapons) //std::pair<std::string, unsigned> instead of auto
	{
		std::cout << it.first << " = $" << it.second << std::endl;
	}
	std::cout << "Which weapon would you like to purcahse? ";
	std::string weaponToPurchase = "";
	std::cin >> weaponToPurchase;
	
	auto selectedWeapon = weapons.find(weaponToPurchase); //auto can be replaced with
	//std::map<std::string, unsigned>::iterator
	
	if(selectedWeapon != weapons.end()) //it was found
	{
		std::cout << "Please enter the number of silver, silver 10 oz, gold, and gold 10 oz"
		<< " you are going to use for the purchase(separated with spaces): ";
		unsigned silver = 0u;
		unsigned silver10oz = 0u;
		unsigned gold = 0u;
		unsigned gold10oz = 0u;
		std::cin >> silver >> silver10oz >> gold >> gold10oz;
		
		unsigned paid = Silver * silver + silver10oz * Silver10oz + 
		Gold * gold + Gold10oz * gold10oz;
		int owed = selectedWeapon->second - paid;
		std::cout << "You gave me $" << paid;
		if(owed > 0)
		{
			std::cout << " and still owe $" << owed << std::endl; //charage them again
		}
		else if(owed < 0)
		{
			std::cout << " which is an extra $" << -owed << std::endl;
		}
		
	}
	else
	{
		std::cout << "That weapon was not found" << std::endl;
	}
	return 0;
}