I've made a program of basic bank transaction. I'm having a hard time figuring out how will that cin >> newb; and cin >> currentb; work out...the program works if you remove the formulas..also i'd like to add if (withdraw <=10000) the program will stop the user from withdrawing but i don't know how will i insert it in there since i've been receiving too much errors if i do so...
and, if you don't mind, how will i post my code so you guys can check my crap program..lol~..
thanks~ :?:

here's the code~... o.o i really don't get it...anyways, i already did the switch thing~...but still and same result..

n#include <iostream>	

using namespace std;
		
int main()                            
{
  int withdraw,deposit,selection,currentb; //currentb serves as current balance
  float newb;
  
  cout << "Welcome to Federal Bank\n";                      
  cout << "What would you like to do today?:\n";
  cout << "1.Withdraw\n";
  cout << "2.Deposit\n";
  cout << "3.Balance Inquiry\n";
  cout << "4.Exit\n";
  cin >> selection;    
                            
  cin.ignore();
  
                         
  if ( selection == 1 ) {
     cout << "Enter the amount you wish to withdraw:";
     cin >> withdraw;
     
     newb=2.50+(currentb-withdraw) //2.50 is processing fee
     
     cout << "Your new balance is:";  
     cin >> newb; //newb serves as new balance
  }
  else if ( selection == 2 ) {            
     cout << "Enter the amount you wish to deposit:\n";
     cin >> deposit;
     
     newb=currentb+deposit
     
     cout << "Your new balance is:\n";
     cin >> newb;          
  }
  else if (selection == 3) {
    cout <<"Your current savings:\n";
    cin >> currentb;
  }
  else if (selection == 4) {
       cout << "Thank you for banking with us!\n";
  }
  else {
       cout << "Error, please enter numbers 1-4 only.\n";
  }     
  cin.get();
}

1) Everywhere you use cin, you are SETTING the value instead of displaying it.
2) Missing semi-colon on lines 25 and 34

For starters, when dealing with money, a transaction is almost never an even-dollar amount (or whatever unit of currency you use). You should deal exclusively in floating-point data types (i.e. "float" or "double") and avoid integer data types.

Second, your equation for calculating a withdrawal (Line 25) actually gives the user a $2.50 bonus/credit to their account, rather than charging a $2.50 fee. Your equation should be more like this: [tex]newb = currentb - (withdraw + 2.50)[/tex]

Correct those issues, then use the tips to see if you can correct your other issues.

Edited 5 Years Ago by Fbody: n/a

okay, now i fixed it...the only problem is the program closes after i enter the desired amount i want to withdraw or deposit...i believe that there's really something wrong with my codes... O.O

#include <iostream>	

using namespace std;
		
int main()                            
{
  int withdraw,deposit,selection,currentb=10000; 
  float newb;
  
  cout << "Welcome to Federal Bank\n";                      
  cout << "What would you like to do today?:\n";
  cout << "1.Withdraw\n";
  cout << "2.Deposit\n";
  cout << "3.Balance Inquiry\n";
  cout << "4.Exit\n";
  cin >> selection;    
                            
  cin.ignore();
  
                         
  if ( selection == 1 ) {
     cout << "Enter the amount you wish to withdraw:";
     cin >> withdraw;        
     cout << "Your new balance is:" << currentb-(2.50+withdraw) << "\n";  
  }
  else if ( selection == 2 ) {            
     cout << "Enter the amount you wish to deposit:\n";
     cin >> deposit;   
     cout << "Your new balance is:" << currentb+deposit << "\n";          
  }
  else if (selection == 3) {
    cout <<"Your current savings:" << " " << currentb << "\n";
  }
  else if (selection == 4) {
       cout << "Thank you for banking with us!\n";
  }
  else {
       cout << "Error, please enter numbers 1-4 only.\n";
  }     
  cin.get();
}

oh great~!...i knew it~.. :D thanks for help guys...

Edited 5 Years Ago by r.cromwell: n/a

This question has already been answered. Start a new discussion instead.