I have a scenario of deposit the amount on a particular address and keep the record of the total amount deposited at this address. The same way one can also withdraw the amount from this address and total should be deducted the withdrawn amount for that particular address.
Here, twick is there can be multiple accounts so there can be multiple addresses and we need to store final amount(deposit/withdraw) account wise. Here we are storing just random amount, not ether.
So my questions are
To store the accounts we need to use the mapping but how to calculate the amount(deposit/withdraw) by using mapping?
can we use the array here?
Thanks
Edit the below part
My program
pragma solidity ^0.4.18;
contract Banking {
uint deposit;
uint amount;
mapping(address => uint) accountBalance;
function setDeposit(uint amt)
{
uint new_deposit = deposit + amt;
accountBalance[msg.sender] = new_deposit;
deposit += amount;
}
function getAmount() constant returns (uint)
{
return(accountBalance[msg.sender]);
}
function withdraw(uint amt)
{
uint withdrawAmount = amt;
uint newBalance = accountBalance[msg.sender] - withdrawAmount;
accountBalance[msg.sender] = newBalance;
}
}