Results 1 to 7 of 7

Thread: Banking system C++

  1. #1
    shane200_ Guest

    Post Banking system C++

    I am doing a banking system in C++ for school and I need some help. There are 3 accounts, when you deposit money in the account is should show you the total amount in the account each time you add money to the account and when you withdraw money it should take away the amount withdraw from the balance that is in the account. Can anyone take a look at my codes and see what I am not doing?

    #include <iostream.h>
    #include <stdlib.h>
    #include <string.h>
    #include <dos.h>


    //the list of function prototypes

    void Deposit();
    void Withdraw();
    void Query();
    void Show();
    void Exit();
    char Menu();

    int acc, dep, with;
    int add = dep + with; //this should add both the deposit and withdraw to give total
    int sub= dep - with;
    //++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++
    int main()
    {
    char choice;

    do{
    choice = Menu();
    switch(choice)
    {
    case 'D' : Deposit(); break;
    case 'W' :Withdraw();break;
    case 'Q' :Query ();break;
    case 'S' :Show(); break;
    case 'E' :Exit ();break;
    default:cout<<"\n\tINVALID ACCOUNT NUMBER ENTERED, PLEASE TRY AGAIN!!!..\n\n\n";

    }

    }while(choice !='E'); // end of while loop



    return 0;
    } //This is the end of the main program

    //++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++

    char Menu()
    {
    char choice;


    cout<<"\tWelcome to Superbank International \n";
    cout<<"====================================";
    cout<<"\n D Deposit \n ";
    cout<<"\n W Withdraw \n";
    cout<<"\n Q Query \n";
    cout<<"\n S Show all \n";
    cout<<"\n E Exit \n";

    cout<<"\n\n Option: ";
    cin>>choice;


    return choice;
    }
    //+++++++++++++++++++++++++++++++++++++++++++++
    void Deposit()
    {
    system ("cls"); //this will clear the screen


    cout<<"Enter the Account Number: ";
    cin>>acc;

    if ((acc == 25784) ||(acc == 36256)||(acc == 43815) )
    {
    cout<<"Enter amount to Deposit:$ ";
    cin>>dep;
    }
    else
    {
    cout<<"\n\n\tSORRY ACCOUNT NUMBER NOT FOUND!!!\n\n";
    }
    cout<<"\tTRANSACTION APPROVED\n\n";
    cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^";
    cout<<"\n\nThe Balance on Account " <<acc<< "is $" <<add<<endl;
    }
    //+++++++++++++++++++++++++++++++++++++++++++++++++
    void Withdraw()
    {
    system ("cls");

    cout<<"Enter the Account Number: ";
    cin>>acc;

    if ((acc == 25784) ||(acc == 36256)||(acc == 43815) )
    {
    cout<<"Enter amount to Withdraw:$ ";
    cin>>with;
    }
    else
    {
    cout<<"\n\n\tSORRY ACCOUNT NUMBER NOT FOUND!!!\n\n";
    }

    cout<<"\tTRANSACTION APPROVED\n\n";
    cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^";
    cout<<"\n\nThe Balance on Account " <<acc<< "is $" <<sub<<endl;
    }
    //++++++++++++++++++++++++++++++++++++++++++++++++
    void Query()
    {
    system("cls");
    cout<<"some text later";
    }
    //++++++++++++++++++++++++++++++++++++++++++++++++++
    void Show()
    {
    system("cls");
    cout<<"It has been printed";
    }
    //+++++++++++++++++++++++++++++++++++++
    void Exit()
    {
    system("cls");
    cout<<"\n\n\t\tTHANK YOU, FOR USING Superbank International ......\n\n";
    exit(1); // quit the programme
    }

  2. #2
    Join Date
    Jun 2002
    Posts
    648
    Rep Power
    0

    Default

    Are you having a problem with the code? If you are, then it would be most helpful to mention that (saves time).

    An observation: hard-coding account numbers in your logic is a "no no". Of course depending on the simplicity of the assignment and your course level you may be able to get away with it. This brings me again to question of what are the requirements/specifications of the program assignment.

  3. #3
    Join Date
    Oct 2004
    Posts
    4,814
    Rep Power
    24

    Default

    Ok, my question is how do you maintain accurate information on each of the accounts? when you call the functions your attempt to calculate the withdraw or deposite, etc.. The logics don't work cout << add; where int add = dep + with; defined before main, will always output zero. I suggest you use structures to maintain bank account info, and perform operations on the structures. Im afraid to tell you that ur program may need lots of recoding.

  4. #4
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    k so i was bored and decided to do this app as i still had the question paper. pretty simple still.

    Code:
    #include "stdafx.h"
    #include <iostream.h>
    #include <conio.h>
    #include <windows.h>
    
    struct accounts{
    	int acnum1;
    	int acnum2;
    	int acnum3;
    	double balance1;
    	double balance2;
    	double balance3;
    };
    
    typedef struct accounts account;
    
    
    account init (account);
    account deposit (account);
    account withdraw (account);
    void query (account);
    void showall (account);
    
    
    int main(int argc, char* argv[])
    {
    	account bank;
    	bank = init (bank);
    	char transaction;
    	while (transaction != 'E'){
    		cout<<"\n++++++++++\n";
    		cout<<"WORLD BANK\n";
    		cout<<"\n++++++++++\n\n";
    
    		cout<<"deposit  -----> <press> D\n";
    		cout<<"withdraw -----> <press> W\n";
    		cout<<"Query	-----> <press> Q\n";
    		cout<<"Show All -----> <press> S\n";
    		cout<<"Exit	-----> <press> E\n";
    		cout<<"\n\n";
    	
    		cout<<"please select your transaction :";
    		cin>>transaction;
    
    		switch(transaction){
    			case 'D':
    				bank = deposit(bank);
    				break;
    			case 'W':
    				bank = withdraw(bank);
    				break;
    			case 'Q':
    				query(bank);
    				break;
    			case 'S':
    				showall(bank);
    				break;
    			case 'E' || 'e':
    				exit(0);
    				break;
    			default:
    				"please select one of the items from the menu item";
    				break;
    		
    		}
    		system("CLS");
    	}
    	return 0;
    }
    
    account init (account buffer){
    	buffer.acnum1 = 11111;
    	buffer.acnum2 = 22222;
    	buffer.acnum3 = 33333;
    	buffer.balance1 = 0;
    	buffer.balance2 = 0;
    	buffer.balance3 = 0;
    	return buffer;
    }
    
    account deposit (account bank){
    	int ac_num;
    	double balance,deposit_amt;
    
    	cout<<"\nenter account number";
    	cin>>ac_num;
    	switch(ac_num){
    		case 11111:
    			cout<< "enter deposit amount ";
    			cin>>deposit_amt;
    			bank.balance1 = bank.balance1 + deposit_amt;
    			balance = bank.balance1;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 22222:
    			cout<< "enter deposit amount ";
    			cin>>deposit_amt;
    			bank.balance2 = deposit_amt + bank.balance2;
    			balance = bank.balance2;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 33333:
    			cout<< "enter deposit amount ";
    			cin>>deposit_amt;
    			bank.balance3 = deposit_amt + bank.balance3;
    			balance = bank.balance3;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance<<".00";
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		default:
    			cout<<"acount number does not exist";
    			break;
    	}
    
    	return bank;
    }
    
    
    
    account withdraw (account bank){
    	int ac_num;
    	double balance,withdrawl_amt;
    
    	cout<<"\nenter account number";
    	cin>>ac_num;
    	switch(ac_num){
    		case 11111:
    			cout<< "enter withdrawl amount ";
    			cin>>withdrawl_amt;
    			bank.balance1 = bank.balance1 - withdrawl_amt;
    			balance = bank.balance1;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 22222:
    			cout<< "enter withdrawl amount ";
    			cin>>withdrawl_amt;
    			bank.balance2 = bank.balance2 - withdrawl_amt;
    			balance = bank.balance2;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 33333:
    			cout<< "enter withdrawl amount ";
    			cin>>withdrawl_amt;
    			bank.balance3 = bank.balance3 - withdrawl_amt;
    			balance = bank.balance3;
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<balance<<".00";
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		default:
    			cout<<"acount number does not exist";
    			break;
    	}
    
    	return bank;
    }
    
    void query (account bank){
    	int ac_num;
    	cout<<"\nenter account number";
    	cin>>ac_num;
    	switch(ac_num){
    		case 11111:
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<bank.balance1;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 22222:
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<bank.balance2;
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		case 33333:
    			system("CLS");
    			cout<<"TRANSACTION APPROVED";
    			cout<<"\n++++++++++++++++++++++\n\n\n\n";
    			cout<<"Balance on your account :\n"<<"#"<<ac_num<<" is $"<<bank.balance3<<".00";
    			cout<<"\n\n\npresss ne button to continue";
    			cout<<endl;
    			getch();
    			break;
    		default:
    			cout<<"acount number does not exist";
    			break;
    	}
    	
    }
    
    void showall (account bank){
    	system("CLS");
    	cout<<"DISPLAYING ALL EXISTING ACCOUNTS";
    	cout<<"\n++++++++++++++++++++++++++++++\n";
    	cout<<"ACCOUNT\t\t\t\tBALANCE\n\n\n";
    	cout<<"-------\t\t\t\t-------\n";
    	cout<<bank.acnum1<<"\t\t\t\t"<<bank.balance1<<"\n";
    	cout<<bank.acnum2<<"\t\t\t\t"<<bank.balance2<<"\n";
    	cout<<bank.acnum3<<"\t\t\t\t"<<bank.balance3<<"\n";
    	cout<<"\n\n\npress ne key to continue";
    	cout<<endl;
    	getch();
    }

  5. #5
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    oh i forgot to add, if you'ld like to you could only have one int acountnum; and one double acountbalance, and create an array of the structure, for the 3 bank accounts. i found this way the best based on what the question paper requested and yeah the ac numbers are aparently to be hardcoded so it says on the paper.
    Last edited by death_knight; Apr 17, 2005 at 02:21 AM.

  6. #6
    shane200_ Guest

    Default

    Death_Knight thx for the codes but I need to understand what I am doing, cause I need to.
    Thx

  7. #7
    Join Date
    Sep 2004
    Posts
    1,905
    Rep Power
    21

    Default

    I want to help you but could you explain again how the accounts work or tell me if I understand correctly.

    A client of the bank must have 3 acounts. Each account has a separate balance. He may deposit/witdraw or query any one of his 3 accounts by typing the account ID. After doing that, he sees the balance from all 3 accounts.

    You may declare:

    struct client
    {
    account[3];
    }

    acount
    {
    balance;
    number;

    Init(AssignedIDNumber, EntryBalance = 0);//Same as create
    Deposit();
    Withdraw();
    }

    //Here you associate an account number to the balance it has, and above you associate the 3 accounts to one client

    Program summary

    Initialize a client information,
    client.acount[0].Init(xxxxx);
    client.acount[1].Init(xxxxx);
    client.acount[2].Init(xxxxx);

    Get Menu option

    Ask for an account number
    Then ask what to do for that account

    Search for the account and get a handle to the client with that account because he has two other account that we need

    for all client
    for all account by that client
    is the an account number match then return client handle and account handle

    Do operation on that acount
    accounthandle->Deposit(Money)

    Display all acounts of client
    clienthandle->acount[0].display()
    clienthandle->acount[1].display()
    clienthandle->acount[2].display()






    You can change the order of some of the proceedure, but the important thing is to save the account number in a variable and call the variable, and do not write (if x == 1235) kind of thing. Also try to keep your data as organised as possible, if you can follow DK's code you will see a lot of structs and that is the big plus.
    Let's act on what we agree on now, and argue later on what we don't.
    Black men leave Barbeque alone if Barbeque don't trouble you

Posting Permissions

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