Like Tree1Likes
  • 1 Post By iMalc

Banking System

This is a discussion on Banking System within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, This is david, Good day, we had a project in our cs class, creating a banking system, i ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    6

    Banking System

    Hi everyone, This is david, Good day, we had a project in our cs class, creating a banking system, i already create one, but i am having a problem with some part, i am using turbo c++

    The output should be the menu first, with 6 choices

    1.open bank account
    2. check balance
    3.deposit
    4.withdraw
    5.close bank account
    6.exit

    the objective is to display this 6 items but first they need to choose number 1 which is the open bank account, if they choose other number, it will come up with error and it will just comeback to the menu that is my first problem, cant do it, second problem after creating a bank account, all the options will be enabled but they cannot create a bank account again, they should close it first

    Here is the code that i created

    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include<iostream.h>
    #include<conio.h>
    
    
    
    
    void main (void)
    {
    char name[32];
    float bal,x;
    int c1,c2;
    c2=bal=0;
    c1=1;
    while (c1 != 0)
    {
    clrscr();
    
    //heading();
        cout<<"========================================\n";
        cout<<"=Welcome to Gomez Bank=\n";
        cout<<"========================================\n";
        cout<<"1. Open Bank Account\n";
        cout<<"2. Check Balance\n";
        cout<<"3. Deposit\n";
        cout<<"4. Withdraw\n";
        cout<<"5. Close Bank Account\n";
        cout<<"6. Exit\n";
        cout<<"Please enter your transaction: ";
    
        cin>>c1;
        clrscr();
    
    switch(c1)
    {
    
    case 1:
    
    cout<<"\nPlease Enter Your Full Name: ";
    gets(name);
    
    
    clrscr();
    do
    {
    cout<<"\n\n\t\t\tNote 500 is the minimuim deposit";
    cout<<"\n\nPlease Enter Your Initial Deposit: ";
    cin>>x;
    }while(x < 500);
    bal = bal + x;
    
    
    getch();
    cout<<"Would you like to do another transaction?\n";
    cout<<"1.Confirm 2.Exit\n";
    cout<<"Enter your choice: ";
    cin>>c2;
    
    if (c2 == 2)
    {c1 = 0;
    break;}
    else if(c2 ==1){
    break;
    }
    
    case 2:
    cout<<"Your current balance is: "<<bal<<"\n";
    cout<<"Would you like to do another transaction?\n";
    cout<<"1.Confirm 2.Exit\n";
    cout<<"Enter your choice: ";
    cin>>c2;
    if (c2 == 2)
    {c1 = 0;}
    else;
    break;
    
    
    case 3:
    cout<<"Enter the value you would like to deposit: ";
    cin>>x;
    while(x<=0)
    {
    cout<<"The value you've entered is invalid. \nPlease try again: ";
    cin>>x;
    }
    bal = bal + x;
    cout<<"Would you like to do another transaction?\n";
    cout<<"1.Confirm 2.Exit\n";
    cout<<"Enter your choice: ";
    cin>>c2;
    if (c2 == 2)
    {c1 = 0;}
    else;
    break;
    
    
    case 4:
    cout<<"Enter the value you would like to withdraw ";
    cin>>x;
    //bal - x < 500
    while (x > bal || x <=0 || bal - x < 500)
    {
    cout<<"The value you've entered is invalid. \nPlease try again: ";
    cin>>x;
    }
    cout<<"Would you like to do another transaction?\n";
    cout<<"1.Confirm 2.Exit\n";
    cout<<"Enter your choice: ";
    cin>>c2;
    if (c2 == 2)
    {c1 = 0;}
    else;
    bal = bal - x;
    break;
    
    
    case 5:
    
    
    case 6:
    c1 = 0;
    break;
    
    }
    };
    
    cout<<"\n\n\n\t\tThank you for using Gomez Banking Systems!";
    getch();
    
    }
    Thanks in advanced, for anyone that can help me

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    At first learn once and forever that main is structured like this
    Code:
    int main()
    {
          ....
          return 0;
    }
    Second once and forever lesson , style your code nicely.See hIndent_style .

    I would set a counter above switch initialized to zero for example.Now in the cases, i would check if when i enter case 1 this counter is zero.If so everything ok and increment the counter by one.If not i would go back to the menu.
    Likewise in all the other cases i would check if the counter is greater than zero.If it is ok.If not, do what you want to handle the error.

    How to get back in the menu?
    With a do - while loop.
    Example
    Goal : Write a small program to have as a menu only one choice : Input a positive number.If the user does so print this value to screen .Otherwise (which means if the user inputs zero or a negative number) display the menu again and let him input again.Consider that user types only integers.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
        int input;
    
        do{
          // Display menu
          cout << "Please, input a positive number" << endl;
    
          // Read input
          cin >> input;
    
         // While the user types non positive numbers
         // execute the loop body again
        }while( input <= 0 );
    
        cout << "Value = " << input << endl;
    
        return 0;
    }
    Now that you saw an example, try to modify your code

    Also David welcome to the forum

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    Thanks, i just modify my program, it is working fine now, thanks a lot for the algorithm, but i had a big problem, my cs professor, wants me to do it using functions, i mean, every code in case, needs to have its own function, please help, this is my new code

    Code:
    #include <stdio.h>
    #include <dos.h>
    #include <stdlib.h>
    #include<iostream.h>
    #include<conio.h>
    
    
    #define OPEN 1
    #define DEPOSIT 2
    #define WITHDRAW 3
    #define BALANCE 4
    #define CLOSEACCOUNT 5
    #define EXIT 6
    
    int main()
    {
    //////////////////////Init
    char name[64];
    bool openBank = false;
    double balance = 0;
    double d = 0; // custom input
    int choice;
    
    bool bQuit = false;
    //////////////////////Start
    while(bQuit == false)
    {
    system("cls");
    
    cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n";
    cout <<"\t\tBANKING SYSTEM"; if(openBank){ cout << "\tName :  \"" << name << "\" Balance : " << balance; }cout  <<"\n";
    cout <<"\t[1] Open an Account\n";
    cout <<"\t[2] Deposit Transaction\n";
    cout <<"\t[3] Withdrawal Transaction\n";
    cout <<"\t[4] Balance Inquiry\n";
    cout <<"\t[5] Close Account\n";
    cout <<"\t[6] Exit\n\n";
    cout <<"\tPlease choose: "; cin >> choice;
    
    cout <<"\n\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n";
    
    Case :
    
    if(choice != OPEN && openBank == false && choice !=CLOSEACCOUNT && choice != EXIT)
    {cout <<"\tPlease, open the account first\n";choice = OPEN;}
    
    //////////////////////Command
    switch(choice) 
    {
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case OPEN :
        if(openBank == false){
        cout <<"\tAccount name : ";cin >> name;openBank = true;balance = 0;
        cout <<"\tWell done " << name << "! The Bank System has been opened !!!\n";
        }
        else
        {cout <<"\tYou'll need to close the account first !\n";choice = CLOSEACCOUNT;goto Case;}
    
    break;
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case DEPOSIT : d = 0;
    while(d < 500){
    cout <<"\tEnter the amount to deposit (min 500) : "; cin >> d;if(d < 500)
    cout <<"\tYou enter is below the minimum deposit. Please enter again.\n\n";}
    balance = balance + d;break;
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case WITHDRAW : d = 501;
    while(d > 500){
    cout <<"\tEnter the amout to withdraw (max 500) : "; cin >> d;if(d > 500)
    cout <<"\tThe maximum is 500. Please enter again.\n\n";
    if(balance - d < 0) {d = 501;
    cout <<"\tThe value is invalid. Please enter again\n\n";}}balance = balance - d;break;
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case BALANCE :
    cout<<"\tYour current balance is: "<<balance<<"\n";
    cout <<"Please enter to go back to the main menu. ";getch();
    break;
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case CLOSEACCOUNT :
    if(openBank == false)cout <<"The bank is closed. No need to close now.\n\n"; 
    else
    {
        cout <<"Please [1] to delete Account and [0] to go back to main menu: "; cin >> choice;
        if(choice == 1){name[0] = 0;openBank = false;}
    }
    break;
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    case EXIT : bQuit = true; break;
    }
    //////////////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////End case commands
    }
    //////////////////////End Bank loop
    return 0;
    }
    //////////////////////End program...

  4. #4
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    I think you skipped this link.Don't.I would say it's a must.I mean i won't read your code unless you style it properly.
    Quote Originally Posted by std10093 View Post
    Second once and forever lesson , style your code nicely.See hIndent_style .

    A will modify for you my own example by the use of functions.I will use one to print the menu, one to read the input and one to print the result.
    Code:
    #include <iostream>
    using namespace std;
    
    void displayMenu(void);
    int readInput(int input);
    void dipsplayResult(int input);
    
    int main()
    {
        int input;
    
        do{
          displayMenu();
          input = readInput(input);
        }while( input <= 0 );
    
        dipsplayResult(input);
    
        return 0;
    }
    
    
    void displayMenu(void)
    {
        cout << "Please, input a positive number" << endl;
    }
    int readInput(int input)
    {
        cin >> input;
        return input;
    }
    void dipsplayResult(int input)
    {
        cout << "Value = " << input << endl;
    }

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Code is a mess, unreadable and horrible.
    Get rid of your char arrays. Use std::string.
    Never use gets. Use std::getline or std::cin >>.
    Stop declaring your variables at the beginning of the function. Declare them near first use.
    Indent your code properly and stick to some good coding style convention, such as the Allman style.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    6
    Hi guys, i know that it is a mess, because i am just starting to learn how to program, please help me, if anyone , can help me to use functions on every switch cases, Thanks

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Everyone has to start somewhere. You've gotten a lot of feedback already. Why not make use of it to update your code?
    If you get rid of the biggest obstacles, it becomes easier to see the smaller obstacles.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,302
    Quote Originally Posted by david123456 View Post
    i am using turbo c++
    Psst: Turbo C++ is a 'compiler' from the stone age that is only really still used in India where their teaching system is so outdated an underfunded that it in no way prepares their graduates for the real world. If it were any older then you'd be wondering where to insert the punch cards.
    Do yourself a favour and download and use a good free compiler such as Visual Studio 2008 Express.
    Salem likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,546
    Quote Originally Posted by iMalc View Post
    ...Do yourself a favour and download and use a good free compiler such as Visual Studio 2008 Express.
    Or an up-to-date compiler such as Visual Studio 2012 Express (don't fear the ui; you can fix it).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Turbo C++ is also used frequently in the Phillipines and Pakistan. But I agree with your sentiment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Banking System
    By punnuindia in forum C++ Programming
    Replies: 9
    Last Post: 04-01-2009, 05:05 PM
  2. Replies: 5
    Last Post: 10-08-2007, 09:44 AM
  3. Banking App
    By comwiz in forum C++ Programming
    Replies: 0
    Last Post: 02-20-2006, 09:12 PM
  4. Develop new Investment Banking Trading System in Singapore
    By pclyne in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 11-14-2005, 07:32 PM
  5. banking progrram
    By sweet2awy in forum C++ Programming
    Replies: 2
    Last Post: 07-24-2003, 06:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21