int main() //@ requires true; //@ ensures true; { struct account *myAccount = account_create(-100); account_deposit(myAccount, 200); int w1 = account_withdraw(myAccount, 50); //assert(w1 == 50); int b1 = account_get_balance(myAccount); //assert(b1 == 150); int w2 = account_withdraw(myAccount, 300); //assert(w2 == 250); int b2 = account_get_balance(myAccount); //assert(b2 == -100); account_dispose(myAccount); return 0; }
int server_transfer(struct Server *s, accountnr_t source, accountnr_t destination, double amount) { struct Account *srcacc = server_getAccountbyID(s, source); struct Account *destacc = server_getAccountbyID(s, destination); if (srcacc != NULL && destacc != NULL) { if (account_withdraw(srcacc, amount)) { account_deposit(destacc, amount); return 1; } } return 0; }
int server_withdraw(struct Server *s, accountnr_t nr, double amount) { struct Account *a = server_getAccountbyID(s, nr); return account_withdraw(a, amount); }