Bank Project Problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Bank Project Problem

  1. #1
    Join Date
    Sep 2012
    Posts
    17

    Post 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 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

    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

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    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. #3
    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. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Bank Project Problem

    Quote Originally Posted by gaby32 View Post
    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. #5
    Join Date
    Sep 2012
    Posts
    17

    Re: Bank Project Problem

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

    void main()
    {
    display_main_menu();
    }

  6. #6
    Join Date
    Sep 2012
    Posts
    17

    Re: Bank Project Problem

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

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Bank Project Problem

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

    void main()
    {
    display_main_menu();
    }
    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. #8
    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. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    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. #10
    Join Date
    Sep 2012
    Posts
    17

    Re: Bank Project Problem

    ms v studio 2008 express edition

  11. #11
    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. #12
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Bank Project Problem

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

  13. #13
    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 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
    	
    } //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();
    }
    updated code

  14. #14
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,131

    Re: Bank Project Problem

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

  15. #15
    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
    {

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center