wow I cant believe i actually new what filip was asking me to do and figured out how to do it. I know I have a long way to go but were definitely making progress here. I just added a require statment to the withdraw function and added a return for the balance minus the amount using the -= operator or whatever its called.
pragma solidity 0.8.1;
contract goinBack{
mapping (address => uint) balance;
address owner;
event depositDone(uint amoubt, address indexed depositedTo);
modifier onlyOwner {
require (msg.sender == owner, âOnly the owner can add and send moneyâ);
_;
}
constructor (){
owner = msg.sender ;
}
function deposit() public payable returns(uint){
balance [msg.sender] += msg.value;
emit depositDone (msg.value, msg.sender);
return balance [msg.sender];
}
function withdraw(uint amount) public returns(uint){
require (balance [msg.sender] >= amount, âyou didnt put that much in the contractâ);
payable (msg.sender).transfer (amount);
return balance [msg.sender] -=amount;
}
function getBalance ( )public view returns(uint){
return balance[msg.sender];
}
function transfer (address recipient, uint amount) public{
require(balance [msg.sender]>=amount, âyou broke broâ);
require(msg.sender!= recipient, âdont send money to yourselfâ);
uint previousSenderBalance = balance[msg.sender]; // this variable was made just to assert that the balance is acurrate
_transfer(msg.sender, recipient, amount);
assert(balance[msg.sender]== previousSenderBalance - amount); // assert is used to check that the balance is what it should be after the ftransfer
}
function _transfer (address from, address to, uint amount) onlyOwner private {
balance [from]-= amount;
balance [to] += amount;
}
}