AshfaqFardin

Bank Account (Dynamic Memory & Struct)

Aug 1st, 2021
1,328
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct bankUser{
  6.     string userName;
  7.     string accountNumber;
  8.     int balance;
  9. };
  10.  
  11. void withdrawMoney(bankUser* user, int money){
  12.     if(money < user->balance){
  13.         user->balance -= money;
  14.     }
  15.     else{
  16.         cout << "You do not have sufficient balance" << endl;
  17.     }
  18. }
  19.  
  20. void depositeMoney(bankUser* user, int money){
  21.     user->balance +=money;
  22. }
  23.  
  24. void checkCurrentBalance(bankUser* user){
  25.     cout << user->balance << endl;
  26. }
  27.  
  28. int main()
  29. {
  30.     bankUser* user = new bankUser;
  31.     user->userName = "Mohammad";
  32.     user->accountNumber = "123456789";
  33.     user->balance = 1000;
  34.    
  35.     cout << "Current Balance: ";
  36.     checkCurrentBalance(user);
  37.    
  38.     depositeMoney(user, 100);
  39.     cout << "Balance after depositeMoney: ";
  40.     checkCurrentBalance(user);
  41.    
  42.     withdrawMoney(user, 200);
  43.     cout << "Balance after withdrawMoney: ";
  44.     checkCurrentBalance(user);
  45.    
  46.  
  47.     return 0;
  48. }
  49.  
RAW Paste Data