-
October 16th, 2012, 03:43 PM
#16
Re: Bank Project Problem
updated code, program still does not work, i'm pulling my hair out now ahhhhh, enough for the day.
Code:
#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;
const float interest = 1.67;
const int cust_account_number = 112280;
string first_name, customer_surname;
double balance, deposit, withdrawl;
int account_exists = 0;
int account_number;
char dat[10], tim[9];
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 switch statement
} // End of loop
while(choice !=5);
} //End of 'display_main_menu' method
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;
account_number = 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 '£'.
}
int main()
{
display_main_menu();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|