# C++ - bank account problems - all help appreciated greatly



## alexaaa (Nov 18, 2008)

Hi i've been assigned to program a very basic bank account in c++ so far i have initialised functions for a withdrawal, deposit, questions for new account. The problem i am having is that when i got to the open new account menu it always seems to direct me to the student account menu. first of all anyways the main reason i am here posting is that i cant seem to grasp the idea of object orientated programming. it is required i break it down into multiple classes and read from each i.e a customer account, menu account, a student one which reads methods such as deposit and withdraw functions and so on. below you can see the code i have so far it is so far in two seperate classes. any tips and pointers would be greatly appreciated as the time of three week deadline gets closer it seems i need to seek further help. I have a great grasp on c++ from a 3d point of view but just cant get my head around this account below is my code so far. i still obviously need to add an array to store customers and somehow only allow deposits and withdrawals once an account is open. thankyou for taking time out your day to look at this.


1st - bank.cpp

#include <iostream>
#include <string> 

using namespace std;

int main()
{
// Declare Variables
int withdraw;
int sqone;
int sqtwo;
int bone;
string colname;
string name;
string sname;
int housenumber;
string postcode;
string dob;
string telno;
double acctbalance, deposit;
char choices;
acctbalance = 0;

//inputs, get the name and initial balance


do
{
cout<<"\n\n-------------------------------------------------\n";
cout << "What do you wish to do?" << endl;
cout << "O open new account" << endl;
cout << "D Deposit Money" << endl;
cout << "W Withdraw Money" << endl;
cout << "B Display Balance" << endl;
cout << "P Bank Account Details" << endl;
cout << "Q Quit" << endl<<endl;cout<<"Enter selection: ";
cin >> choices;
switch (choices)
{
//add account type options here under letter O
case 'O':
case 'o':
{
{
cout<<"\n\n-------------------------------------------------\n";
cout << "What Account Do You Wish To Open?" << endl;
cout << "S Student Account" << endl;
cout << "C Current Account" << endl;
cout << "B Business Account" << endl;
cout<<"Enter selection: ";
cin >> choices;
}
}





//STUDENT ACCOUNT 
case 'S':
case 's':
{
cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
cout<<"---------------------------------------------------------"<<endl;
cout<<"Are You A Full Time Student?"<<endl;
cin>>sqone;
if (sqone == 0)
{
cout << "sorry that is not a valid option"<< endl;
break;
}
if (sqone == 2)
{
cout<<"Sorry You Are Not Valid For This Account"<<endl;
break;
}
else if (sqone == 1)
{
cout<<"Thankyou"<<endl;
cout<<"Have You Got Documentation To Support Your Course And Accomadation?"<<endl;
cin>>sqtwo;
if (sqtwo == 0)
{
cout << "sorry that is not a valid option"<< endl;
 break;
}
if (sqtwo == 1)
{
cout<<"Thankyou you are elegible for this account"<<endl;
cout<<"------------------------------------------"<<endl;
cout << "Colleague Name: ";
cin >> colname;
cout << "Enter First Name: ";
cin >> name;
cout << "Enter Surname: ";
cin >> sname;
cout << "House Number: ";
cin >> housenumber;
cout << "Post Code: ";
cin >> postcode;
cout << "Date Of Birth: ";
cin >> dob;
cout << "Telephone Number: ";
cin >> telno;
cout << "Please enter initial balance: ";
cin >> acctbalance;
break;


}
else if (sqtwo == 2)
{
cout<<"Sorry You Are Not Valid For This Account"<<endl;
break;
}



//BUSINESS ACCOUNT
case 'c':
case 'C':
{
cout<<"Please Answer The Following Questions / 1 = Yes, 2 = No "<<endl;
cout<<"---------------------------------------------------------"<<endl;
cout<<"Have you got documentation showing your business details?"<<endl;
cin>>bone;
if (bone == 0)
{
cout << "sorry that is not a valid option"<< endl;
break;
}
if (bone == 2)
{
cout<<"Sorry You Are Not Valid For This Account"<<endl;
break;
}
else if (bone == 1)
{
cout<<"Thankyou you are elegible for this account"<<endl;
cout<<"We Will Now Proceed To Open This Account For You?"<<endl;
break;

}
}
}
}



case 'D':
case 'd':
{
cout << "Enter amount to be deposited: "<< endl;
cin >>deposit;
if (deposit > 0)
{
acctbalance = acctbalance + deposit;
if (deposit >= 10000)
cout <<"Big Money!"<<endl;
break;
}
if (deposit == 0 || deposit < 0)
{
cout <<"Amount must be greater than 0";
break ;
 }
}
case 'B':
case 'b':
{
cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
if (acctbalance ==0)
cout <<"Big Money!"<<endl;
break;
}
case 'W':
case 'w':
{
cout<<"Please enter amount to withdraw "<<endl;
cout<<"Withdrawal must be multiple of 10"<<endl;
cin>>withdraw;
if (withdraw == 00)
{
cout << "Can't withdraw 0 dollars"<< endl;
break;
}
if (withdraw < 0)
{
cout<<"Must be a positive number"<<endl;
break;
}
if (withdraw > acctbalance)
{
cout<<"Can't withdraw more than balance"<<endl;
break;
}
if ((withdraw % 10) !=0)
{
cout<<"amount must be a multiple of 20"<<endl;
break;
}
else
{
acctbalance=acctbalance - withdraw;
cout<<"Here is your money. Enjoy!"<< endl;
break;
}
case 'P':
case 'p':
{
cout << "\n\n"<<endl;
cout <<"Personal Details"<<endl;
cout <<"First Name : "<<name<<endl;
cout <<"Surname : " <<sname<<endl;
cout <<"house number : " <<housenumber<<endl;
cout <<"post code : " <<postcode<<endl;
cout <<"telephone number : " <<telno<<endl;

cout <<"Your current balance is £ "<<acctbalance<<'.'<<endl;
if (acctbalance ==0)
cout <<"Big Money!"<<endl;
break;
}
}

case 'Q':
case 'q':
{
cout<<"Thank for using our services have a nice day!"<<endl;
break;
}
}
}while (choices != 'q' && choices != 'Q');
return 0;
}



2nd - Account.h


#include <iostream>
#include <string>

using namespace std;

class Account
{
double money; // amount of money held by this account
double interestRate; // a monthly or yearly interestrate, depending on how the account is to be used.


public:

// create an account with an initial amountand a specified interest rate
Account(double amount, double percent)
{
money = amount;
interestRate = percent;
}

// return the account's balance
double balance()
{
return money;
}

// add money to the account
void deposit(double amount)
{
money += amount;
}

// substract money from the account
void withdraw(double amount)
{

}

// add money according to the interest rate.
void addInterest()
{
money *= (1 + interestRate/100.0);

}

};


----------

