// Title: Bank Account Program
// Author:
// Descripition: A bank account program that lets the user open an account by adding a
// customer name then adding a balance to the account, also lets you make a withdrawl from
// the account and add a deposit to the account and the user can add interest to the account
// which is calculated at 1.67% and the account number used to setup the account is 00112280
#include "stdafx.h"
#include <iostream>
#include <string>
#include <iomanip> // setprecision() funcion
#include <conio.h> // _getch() function
#include <ctime> // add system time and date
using namespace std;
// Global Constant Declerations
const float interest = 1.67;
const int account_number = 112280;
// Global Variables
string customer_first_name, customer_surname;
double balance, deposit, withdrawl;
int account_exists = 0;
int cust_account_number;
char dat[10], tim[9];
// Method Definition
void display_main_menu();
void open_account();
void account_withdrawl();
void account_deposit();
void add_interest();
void display_account_details();
void exit();
void display_main_menu()
{
int choice;
do
{
system ("cls");
_strdate(dat);
_strtime(tim);
cout << endl << "Todays date is: " << dat << " and the time is " << tim << endl << endl;
cout << "\t Bank Account Menu" << endl;
cout << "\t_________________________" <<endl << endl;
cout << "\t1. Open an account " << endl
<<"\t2. Make a withdrawl " << endl
<<"\t3. Make a deposit " << endl
<<"\t4. Add interest " << endl
<<"\t5. Exit " << endl << endl
<<"Enter Choice: ";
cin >> choice;
system ("cls");
switch(choice)
{
case 1: open_account();
break;
case 2: account_withdrawl();
break;
case 3: account_deposit();
break;
case 4: add_interest();
break;
case 5: exit();
cout << "\t Exit main menu" << endl << endl;
break;
}// End of display main menu
} // End of switch statement
} // End of loop
void open_account()
// allocate account number, get initial balance and confirmation message that account has been
// created
{
cout << "Enter customer first name: ";
cin >> customer_first_name;
cout << "Enter customer surname: ";
cin >> customer_surname;
cust_account_number = cust_account_number + 1;
cout << endl << "Enter initial balance: ";
cin >> balance;
cout << endl << "Congratulations on opening your new bank account with us" << endl << endl;
account_exists = 1;
display_account_details();
cout << endl << endl << "Please press any key to return to the main menu" << endl << endl;
_getch();
}
void account_withdrawl()
{
// if account exists prompt user for withdrawal amount if sufficient funds to withdraw cash
// or else print account does not exist message
if (account_exists == 1)
{
cout << endl << "Enter how much you wish to withdraw: ";
cin >> withdrawl;
if (withdrawl > balance)
cout << "You have insufficient funds in your bank account to cover this withdrawl!"
<< endl;
else
{
balance = balance - withdrawl;
cout << endl << (char)156 << withdrawl << " has been withdrawn from your account. " << endl;
display_account_details();
}
} //End of first 'if' statement.
else
cout << "Account does not exist!" << endl << "Press any key to return to the main menu. " << endl;
_getch();
}
void account_deposit()
{
/*if account exists prompt for deposit amount, add deposit to balance
else print account does not exist message
end if
*/
if (account_exists == 1)
{
cout << "Please enter the amount you wish to deposit: ";
cin >> deposit;
balance + balance + deposit;
display_account_details();
}// End of True "if" statement
else
cout << "Account does not exist!" <<endl << "Press any key to return to the main menu." << endl;
_getch();
}
void add_interest()
{
float interest_added = 0;
if (account_exists == 1)
{
interest_added = balance * (interest/100);
cout << (char) 156 << fixed << setprecision(2) <<
interest_added << "has been added to the following account." << endl << endl;
balance = balance + interest_added;
display_account_details();
} // End of true 'if' statements
else
cout << "Account does not exist!" << endl << "Press any key to return to the main menu. " << endl;
_getch()
}
void display_account_details()
{
cout << "\t Account Details" << endl << endl;
cout << "\t Customer Name: " << customer_first_name << " " <<
customer_surname << endl;
cout << "\t Account Number: " << "00" << account_number << endl;
cout << "\t Current Balance: " << (char)156 << fixed << setprecision(2)
<< balance << endl; //(char)156 inserts the symbol '£'.
}
void main()
(
display_main_menu();
}
Hi Paul
I have a few problems on the code for the bank account project, it will be appreciated if you can have a look for me.
Problem 1:
#include "stdafx.h"
In c++ the word include in the above line is highlighted in red.
Problem 2:
} // End of switch statement
} // End of loop
void open_account()
// allocate account number, get initial balance and confirmation message that account has been
// created
{
In c++ the bracket next to // End of loop is highlighted in red.
Problem 3:
_getch()
}
void display_account_details()
In c++ the bracket above void display_account_details is highlighted in red.
Problem 4:
void main()
}
display_main_menu();
}
In c++ the both the opening and closing bracket is highlighted in red and also the ; after display_main_menu();
Thanks