Bank Project Problem
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: Bank Project Problem

1. Junior Member
Join Date
Sep 2012
Posts
17

## Bank Project Problem

Code:
```// 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;

const float interest = 1.67;
const int account_number = 112280;

string customer_first_name, customer_surname;
double balance, deposit, withdrawl;
int account_exists = 0;
int cust_account_number;
char dat[10], tim[9];

void open_account();
void account_withdrawl();
void account_deposit();
void display_account_details();
void exit();

{
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;
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();

}

{
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()
(
}```
Hi

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()
}
}

In c++ the both the opening and closing bracket is highlighted in red and also the ; after display_main_menu();

Thanks

2. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

Do requires a matching while

Your comments on the closing braces don't match what they do.

balance + balance + deposit; should be balance = balance + deposit;
Last edited by GCDEF; October 16th, 2012 at 09:34 AM.

3. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

hello

Thanks i got that: balance = balance + deposit;

but I'm still having the above 4 problems in my first post

4. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

Originally Posted by gaby32
hello

Thanks i got that: balance = balance + deposit;

but I'm still having the above 4 problems in my first post
Did you understand what I meant when I said do requires a matching while? The others are really pretty self-explanatory. Also, look very closely at your main function. Look at what is really there, not what you think is there.
Last edited by GCDEF; October 16th, 2012 at 02:05 PM.

5. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

update problem 4 sorted, i had wrong bracket above display_main_menu();

void main()
{
}

6. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

update problem 3 sorted added ; at end of getch() so it becomes getch();

7. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

Originally Posted by gaby32
update problem 4 sorted, i had wrong bracket above display_main_menu();

void main()
{
}
Also, while some compiler will accept void main(), they shouldn't. It's illegal syntax. main must return an int. You'd be better off getting into that habit so your code will still work on conforming compilers.

8. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

thanks for that tip.

but why is #include "stdafx.h" highlighted in red?
Last edited by gaby32; October 16th, 2012 at 02:43 PM.

9. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

What compiler are you using that highlights things in red? Does that file exist? Just delete the #include statement. You don't need it for your app anyway.

10. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

ms v studio 2008 express edition

11. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

closing bracket for problem 2 still presets, can't see any silliy mistakes

} //End of 'display_main_menu' method

12. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

Originally Posted by gaby32
closing bracket for problem 2 still presets, can't see any silliy mistakes
I've already told you twice what the problem is.

13. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

Code:
```#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 customer_first_name, customer_surname;
double balance, deposit, withdrawl;
int account_exists = 0;
int account_number;
char dat[10], tim[9];

void open_account();
void account_withdrawl();
void account_deposit();
void display_account_details();
void exit();

{
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:
break;
case 5:
exit();
cout << "\t Exit main menu" << endl << endl;
break;

}// End of switch statement

} // End of loop

} //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();

}

{
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()
{
}```
updated code

14. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: Bank Project Problem

As I said, I've already told you the problem twice in this thread.

15. Junior Member
Join Date
Sep 2012
Posts
17

## Re: Bank Project Problem

Added while(choice !=5); see below

}// 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
{

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Click Here to Expand Forum to Full Width