Results 1 to 15 of 23

Thread: C PLUS PLUS help!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default

    Ok this is the finished bank program that I attached to the post. It works and does the things I wanted it to:
    1. Withdraw from checking acc
    2. Withdraw from Savings acc
    3. deposit to checkings acc
    4. deposit to savings acc
    5. see your balance in checkings
    6. see your balance in savings
    7. quit

    I have a pin number that is installed and it is 7410.

    Now, I have to make data files of at least 5 customers using sequential access files. I have to put a name, a pin, a checking balance, and a savings balance of the customer. Where do I start.?


    //Header files.
    #include <conio.h>
    #include <iostream>
    #include <iomanip>
    #include <fstream>

    //prints out the textfile.
    using namespace std;
    ofstream outfile ("AtmUpdate.txt");

    int pinnumber = 7410;
    double checkbalance = 314.19;
    double savebalance = 708.03;

    struct ATM
    {
    char name[41];
    int pinnumber2;
    int option;
    double withdrawlcheckingamount;
    double withdrawlsavingsamount;
    double depositsavingsamount;
    double depositcheckingamount;
    double depositsbalance;
    double deposit;
    double withdrawl;
    double endingbalance;
    };
    ATM record;

    void ProgramDescription(); //
    int Get_pinnumber(); //
    int Get_pinnumber1(); //
    int Get_pinnumber2(); //
    int Get_option(); //
    int withdrawlC(); //
    int withdrawlS(); //
    int depositC(); //
    int depositS(); //
    int calcwithc(); //
    int calcwiths(); //
    int calcdepc(); //
    int calcdeps(); //

    int main()
    {
    ATM record;

    ProgramDescription();
    Get_pinnumber();
    Get_option();

    outfile.open("BANK.DAT",ios::app);

    getch();
    return 0;
    }

    //Program Description.
    void ProgramDescription()
    {
    cout << "This program simulates an ATM machine.\n\n";
    cout << "Welcome to Banks-O-Million.\n\n";
    cout << "Please hit any key to continue.\n\n";
    getch();
    }

    //Gets PIN number.
    int Get_pinnumber()
    {
    system ("cls");
    cout << "Please enter your 4 digit PIN number.\n";
    cin >> record.pinnumber2;

    if (pinnumber == record.pinnumber2)
    {
    cout << "You may move on to the next screen. Hit any key to get there." << endl;
    getch();
    }

    else
    {
    cout << "You have entered the wrong PIN number. You have 2 more attempt(s) left. Please hit any key to get to the next screen and try again." << endl;
    getch();
    Get_pinnumber1();
    }
    }

    //if they get it wrong, it goes here.
    int Get_pinnumber1()
    {

    cout << "Please enter your 4 digit PIN number.\n";
    cin >> record.pinnumber2;

    if (record.pinnumber2 == pinnumber)
    {
    cout << "You may move on to the next screen. Hit any key to get to the next screen." << endl;
    getch();
    }

    else
    {
    cout << "You have entered the wrong PIN number. You have one more attempt(s) left. Please hit any key to get to the next screen, and try again." << endl;
    getch();
    Get_pinnumber2();
    }
    }

    //If they get it wrong again, it goes here.
    int Get_pinnumber2()
    {

    cout << "Please enter your 4 digit PIN number.\n";
    cin >> record.pinnumber2;

    if (record.pinnumber2 == pinnumber)
    {
    cout << "You have entered the correct PIN number. Please hit any key to get to the next screen." << endl;
    }

    else
    {
    cout << "You have entered the wrong PIN number 3 times incorrectly. This ATM is now eating up your card.\a\a\a\a\a\a\a." << endl;
    return 0;
    }
    }

    //Gets their option for what they want to do.
    int Get_option()
    {
    system ("cls");
    cout << "What would you like to do today: \n";
    cout << "Enter an option:\n\n";
    cout << "1-Withdraw from your Checking account\n\n";
    cout << "2-Withdraw from Savings account.\n\n";
    cout << "3-Deposit to Checking account.\n\n";
    cout << "4-Deposit to Savings account.\n\n";
    cout << "5-See your balance in your checking account.\n\n";
    cout << "6-See your balance in your savings account.\n\n";
    cout << "7-Quit.\n\n";
    cout << "Option: ";
    cin >> record.option;
    system ("cls");
    //prints out atm option chosen.
    switch (record.option)
    {

    //withdrawal from checking option.
    case 1:
    withdrawlC();
    break;

    //withdrawl from savings option.
    case 2:
    withdrawlC();
    break;

    //Deposit to checking account
    case 3:
    depositC();
    break;

    //Deposit to savings account.
    case 4:
    depositS();
    break;

    //See checking balance.
    case 5:

    cout << "You currently have $" << checkbalance << " in your checking account.\n";
    cout << "Hit any key to end the program";
    return 0;
    break;

    //See savings balance.
    case 6:

    cout << "You currently have $" << savebalance << " in your savings account.\n";
    cout << "Hit any key to end the program";
    return 0;
    break;

    //Quit.
    case 7:
    cout << "Thank you for using this ATM. Please hit any key to exit.";
    return 0;

    //All other cases, invalid

    default:
    cout << "\n";
    cout << record.option;
    cout << " is invalid. Please try again.";
    Get_option();
    }
    }

    int withdrawlC()
    {
    cout << "\nHow much do you wish to withdraw? ";
    cin >> record.withdrawlcheckingamount;
    calcwithc();

    return 0;
    }

    int calcwithc()
    {
    double checkbalance = 314.19;
    double savebalance = 708.03;

    record.endingbalance = checkbalance - record.withdrawlcheckingamount;
    cout << "\nYour new balance is: $";
    cout << record.endingbalance;
    }

    int withdrawlS()
    {
    cout << "\nHow much do you wish to withdraw? ";
    cin >> record.withdrawlsavingsamount;
    calcwiths();
    return 0;
    }

    int calcwiths()
    {
    double savebalance = 708.03;

    record.endingbalance = savebalance - record.withdrawlsavingsamount;
    cout << "\nYour new balance is: $";
    cout << record.endingbalance;

    return 0;
    }

    int depositC()
    {
    cout << "\nHow much do you wish to deposit? ";
    cin >> record.depositcheckingamount;
    calcdepc();
    }

    int calcdepc()
    {
    double checkbalance = 314.19;

    record.endingbalance = checkbalance + record.depositcheckingamount;
    cout << "\nNew balance: $";
    cout << record.endingbalance;

    return 0;
    }

    int depositS()
    {

    cout << "\nHow much do you wish to deposit? ";
    cin >> record.depositsavingsamount;
    calcdeps();
    }

    int calcdeps()
    {
    double savebalance = 708.03;

    record.endingbalance = savebalance + record.depositsavingsamount;
    cout << "\nNew balance: $";
    cout << record.endingbalance;


    return 0;
    }
    Attached Files Attached Files
    Last edited by Mr. Hid-Man; 05-01-2006 at 04:36 PM.

Posting Permissions

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