Update implemented removeCurrency

This commit is contained in:
Lev
2021-06-12 20:46:33 -05:00
parent 40750a8d28
commit 016d72d795
4 changed files with 30 additions and 2 deletions

View File

@ -24,6 +24,29 @@ void Wallet::insertCurrency(std::string type, double amount)
currencies[type] = balance;
}
bool Wallet::removeCurrency(std::string type, double amount)
{
double balance;
if(amount < 0)
{
return false;
}
if(currencies.count(type) == 0) // currency not in wallet
{
return false;
}
else // is there, do we have enough?
{
if(containsCurrency(type, amount))
{
currencies[type] -= amount;
return true;
}
else // didn't have enough
return false;
}
}
bool Wallet::containsCurrency(std::string type, double amount)
{
if(currencies.count(type) == 0) // not in wallet yet
@ -44,4 +67,4 @@ std::string Wallet::toString()
s += currency + " : " + std::to_string(amount) + "\n";
}
return s;
}
}