Update implemented insert and contains functions

This commit is contained in:
Lev
2021-06-12 19:15:27 -05:00
parent 3f1e58cae4
commit 28e8407e6b
2 changed files with 21 additions and 2 deletions

View File

@ -7,12 +7,31 @@ Wallet::Wallet()
void Wallet::insertCurrency(std::string type, double amount)
{
double balance;
if(amount < 0)
{
throw std::exception{};
}
if(currencies.count(type) == 0) // not in wallet yet
{
balance = 0;
}
else
{
balance = currencies[type];
}
balance += amount;
currencies[type] = balance;
}
bool Wallet::containsCurrency(std::string type, double amount)
{
return false;
if(currencies.count(type) == 0) // not in wallet yet
{
return false;
}
else
return currencies[type] >= amount;
}
std::string Wallet::toString()