hey guys Im here again :P
Here is my code for bank account class..
#include<iostream>
#include<iomanip>
using namespace std;
class account
{
private:
int account_balance;
public:
account(int acc) //constructor
{
if(acc>=0)
{
account_balance=acc;
}
else
{
account_balance=0;
cout<<"initial balance is invalid"<<endl;
}
}
int credit(int ammount) //credit member function
{
return account_balance+ammount;
}
int debit(int deb) //debit member function
{
if(deb<=account_balance)
{
return account_balance-deb;
}
else
{
return account_balance;
cout<<"Debit ammount exceeded account balance"<<endl;
}
}
};
/* main body
*/
int main()
{
int acc,ammount,deb;
cout<<"enter account balance"<<endl;
cin>>acc;
account obj(acc);
cout<<"enter credit ammount"<<endl;
cin>>ammount;
cout<<"after adding credit ammount, your account balance is:"<<setw(5)<<obj.credit(ammount)<<endl;
cout<<endl<<"enter debit ammount"<<endl;
cin>>deb;
cout<<"after deducting debit ammount, your account balance is:"<<setw(5)<<obj.debit(deb)<<endl;
return 0;
}
there is no any error in my code but logical error. Problem is when i enter credit ammount it does not adds it into account balance. And when i enter debit ammount it does not deducts it from account balance as well. Anyone please help.Im stuck here..