c++ - Cannot figure out how to do this code -


i have been working on project simulates bank account. user can deposit, withdraw, , have withdraws , deposits displayed on screen. @ top of selection menu needs current balance. so, savings : 100. , whenever deposit money or withdraw money need balance change correct amount. amount starts @ $100. if deposit or withdraw money work first time, on second time gets reset $100 , transaction done. how can make balance stay correct amount without resetting? school project , not looking provide me code. seeking tips or guidance in right direction. here code int main() :

int main () {     saving sa;     creditcard cca;     checking ca;      string n;     int option;     int exit = 1;     int x = 1;     do{     cout << endl;     cout << "checking balance:" << ca.getbalance() << "       " << "savings balance:" << sa.getbalance() << "       " << "credit card balance:" << cca.getbalance() << endl;     cout << endl;      cout << " (1) savings deposit " << endl;     cout << " (2) savings withdrawel " << endl;     cout << " (3) checking deposit " << endl;     cout << " (4) write check " << endl;     cout << " (5) credit card payment " << endl;     cout << " (6) make charge " << endl;     cout << " (7) display savings " << endl;     cout << " (8) display checkings " << endl;     cout << " (9) display credit card " << endl;     cout << " (0) exit " << endl;     cin >> option;      switch ( option )      {         case 1 : {                  double samtd;                  cout << " please enter how deposit savings " << endl;                  cin >> samtd;                  sa.makedeposit(samtd);                  break;                  };         case 2 : {                  int samtw;                  cout << " please enter how withdraw "<< endl;                  cin >> samtw;                  sa.dowithdraw(samtw);                  break;                  }         case 3 : {                  double camtd;                  cout << " please enter how deposit checkings " << endl;                  cin >> camtd;                  ca.makedeposit(camtd);                  break;                  }         case 4 : {                  double camtw;                  int chknum;                  cout << " please enter how wrote on check " << endl;                  cin >> camtw;                  cout << " please enter check number " << endl;                  cin >> chknum;                  ca.writecheck(chknum, camtw);                  break;                  }         case 5 : {                  double ccmkp;                  cout << " please enter amount deposit " << endl;                  cin >> ccmkp;                  cca.makepayment(ccmkp);                  break;                  }         case 6 : {                  double doc;                  string nm;                  cout << " please enter amount charged credit card " << endl;                  cin >> doc;                  cout << " please enter charge made " << endl;                  cin >> nm;                  getline(cin, nm);                  cca.docharge(nm,doc);                  break;                  }         case 7 : {                  sa.display();                  break;                  }         case 8 : {                  ca.display();                  break;                  }         case 9 : {                  cca.display();                  break;                  }         case 0 : exit = 0;                  break;         default : exit = 0;                  cout << " error ";     }     }     while(exit==1);      return 0; } 

and here balance being set :

double curbalance = 100; void account::setbalanced(double balance) // deposit {     itsbalance = balance; }  void account::setbalancew(double balance) // withdraw {     double newbalance = curbalance - balance;     itsbalance = newbalance; }  double account::getbalance() {     return itsbalance; } 

and here code option 2 in menu calling :

int saving:: dowithdraw(int amount)

{     if (amount > 0)     {         (int = 9; != 0; i--)         {              last10withdraws[i] = last10withdraws[i-1];         }         last10withdraws[0] = amount;          setbalancew(amount);       }     else     {         cout << " error. number must greater zero. " << endl;     }     return 0; } 

any ideas? cannot balance remain accurate.

your implementation performing deposit appears incorrect. should be:

void account::setbalanced(double balance) // deposit {     itsbalance += balance; } 

notice adding amount being deposited current balance, instead of explicitly setting it's value. ken pointed out same applies performing withdraw.

void account::setbalancew(double balance) // withdraw {     itsbalance -= balance; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -