OK...Here's the deal, I implemented a class for banking application with simple functions like
1.Withdrawal
2.Deposit
3.Balance Inquiry
4.Creation of Account.
I have this code with me and it works fine until I create individual account,after which it is entering infinite loop.I checked the code and its not givin me any clues for error whatsoever.
I plan to create account and then perform above functions but its just not running properly.I also need suggestions for any improvements regarding string usage and class implementation.
Do I need to use file to read the account details? Or it will work without it.
Here's the code below.
1.Withdrawal
2.Deposit
3.Balance Inquiry
4.Creation of Account.
I have this code with me and it works fine until I create individual account,after which it is entering infinite loop.I checked the code and its not givin me any clues for error whatsoever.
I plan to create account and then perform above functions but its just not running properly.I also need suggestions for any improvements regarding string usage and class implementation.
Do I need to use file to read the account details? Or it will work without it.
Here's the code below.
Code:
#include<iostream> #include<string> using namespace std; using std::cout; using std::endl; using std::string; class account { string name; string type; int acc_no; float bal; public: void create(string &n,string &t,int an,float bl) { name.assign(n); type.assign(t); acc_no=an; bal=bl; } void deposit(float dep) { bal=bal+dep; cout<<"You deposited "<<dep<<"and your new balance is "<<bal; } void withd(float dep) { bal=bal-dep; cout<<"Your withdrawl amount is "<<dep<< " and your balance is "<<bal; } void display(void); }; void account::display(void) { cout<<"Name "<<name<<endl; cout<<"Balance "<<bal; } int main() { account ac; string a_name; string a_type; // char c; int a_no,ch; float a_bal; // cout<<"Do you have an account in bank? Y/N\n"; // cin>>c; // if(c=='N') // { cout<<"Enter your details in following manner\n"; cout<<"Name of the account holder \t"; cin>>a_name; cout<<"Type of the account whether savings or current \t "; cin>>a_type; cout<<"Account Number \t"; cin>>a_no; cout<<"Initial Balance \t"; cin>>a_bal; ac.create(a_name,a_type,a_no,a_bal); cout<<"Your account has been created!!!"; // } // else // { cout<<"Enter your options as follows\n"; cout<<"1.Deposit\n"; cout<<"2.Withdrawl\n"; cout<<"3.Balance Enquiry"; while(ch!=4) { switch(ch) { case 1: cout<<"Enter amount to be deposited\n"; cin>>a_bal; ac.deposit(a_bal); break; case 2: cout<<"Enter amount to be withdrawled"; cin>>a_bal; ac.deposit(a_bal); break; case 3: ac.display(); break; case 4: exit(0); default: cout<<"Please enter proper option!!"; // } } } return 0; }
Comment