Update implemented removeCurrency
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user