My Program is compiling, but it wont stop running. Can you please help me?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tigerlily
    New Member
    • Nov 2006
    • 2

    My Program is compiling, but it wont stop running. Can you please help me?

    // Program to create new accounts, perform deposits, withdrawals, and bank
    //inquiries
    #include<iostre am>
    #include<fstrea m>
    using namespace std;
    void menu();
    int read_accts(int [], double [], int);
    void withdrawal(int [], double [], int);
    void deposit(int [], double [], int);
    int new_acct(int [], double [], int);
    void balance(int [], double[], int);
    int main()
    {
    char answer;
    int a, num_elems, max_elems;
    int acctnum[6] = {123456,781912, 238427,581493,9 41357,842364};
    double balance[6] = {500000,100,654 00,500,1000,20} ;

    max_elems = read_accts (acctnum, balance, 100);
    num_elems = read_accts (acctnum, balance, 100);

    while (num_elems <=6){
    read_accts(acct num, balance, max_elems);
    if (answer == 'W') withdrawal(acct num, balance, num_elems);
    if (answer == 'D') deposit(acctnum , balance, num_elems);
    }

    do {
    menu();
    cout << "Which banking transaction would you like to use? Enter Q to quit";
    cout << " the transaction " << endl;
    cin >> answer;

    }while ((answer != 'Q') && (answer != 'q'));

    system ("pause");
    return 0;

    }

    // Function: read_accts
    // Input:
    // account numbers and their current balances
    // Process:
    // reads in the account number and its balance
    // Output:
    // prints the account number and its balance

    //Function to read in the account numbers and their balances
    int read_accts (int acctnumarray [], double balancearray [], int maxelems)
    {
    int a, elemcount = 0;
    double balance;
    for (a = 0; a <=6; a++){

    // declare and open input file
    // fstream infile("c:\\Dev-Cpp\\bankprogin put.txt");
    // ifstream infile(“con”); //un-comment for debugging

    cout << "The account number is " << acctnumarray[a];
    cout << "and its balance is " << balancearray[a] << endl;

    }

    return elemcount;


    }

    // Function: menu
    // Input:
    // none
    // Process:
    // creates a menu for the user
    // Output:
    // A menu is printed

    // Function to print the menu
    void menu()
    {
    cout << " Menu of Transactions" << endl;
    cout << " W = withdrawal" << endl;
    cout << " D = deposit" << endl;
    cout << " N = new account" << endl;
    cout << " B = balance" << endl;
    cout << " Q = quit" << endl;
    return;
    }

    // Function: Withdrawal
    // Input:
    // none
    // Process:
    // determines amount of money that the user wants to take out
    // Output:
    // the amount of money to be withdrawn

    // Function to make a withdrawal
    void withdrawal (int acctnumarray [], double balancearray [], int numelems)
    {
    int with = 0;
    int acctnum, a;

    cout << "Enter your account number: - end with EOF" << endl;
    cin >> acctnum;
    for (a = 0; a <= numelems; a++);
    if (acctnum == acctnumarray[a])
    {
    cout << "How much money would you like to withdraw?" << endl;
    cin >> with;
    }
    else if (acctnum != acctnumarray[a])
    {
    cout << "This is an invalid account number." << endl;
    }

    if (with <= balancearray[a])
    {
    cout << "Your account does not have a sufficient amounts of funds";
    cout << "to proceed with this transaction." << endl;
    }

    return;
    }

    // Function: Deposit
    // Input:
    // none
    // Process:
    // determines amount of money that the user wants to take out
    // Output:
    // the amount of money to be withdrawn

    //Function to make a deposit
    void deposit (int acctnumarray [], double balancearray [], int numelems)
    {
    int dep = 0;
    int acctnum, a;

    cout << "Enter your account number:" << endl;
    cin >> acctnum;
    for (a = 0; a <= numelems; a++);{
    cout << "How much money would you like to deposit?" << endl;
    cin >> dep;
    if (acctnum != acctnumarray[a]);
    cout << "This account does not exist." << endl;

    }
    return;
    }

    // Function: balance
    // Input:
    // none
    // Process:
    // determines amount of money that the user has left in their account
    // Output:
    // the amount of money to be withdrawn

    //Function to tell you how much money is in your account
    //void balance (int acctnumarray [], double balancearray [], int numelems)
    //{
    //}
  • MariyaGel
    New Member
    • Nov 2006
    • 7

    #2
    Im not exactly sure if this is what you wanted since im new at this but i got the program to stop being in an endless loop and you can fix up the rest from here.

    Here it is:

    #include<iostre am>
    #include<fstrea m>
    using namespace std;
    void menu();
    int read_accts(int [], double [], int);
    void withdrawal(int [], double [], int);
    void deposit(int [], double [], int);
    int new_acct(int [], double [], int);
    void balance(int [], double[], int);
    int main()
    {
    char answer;
    int a, num_elems, max_elems;
    int acctnum[6] = {123456,781912, 238427,581493,9 41357,842364};
    double balance[6] = {500000,100,654 00,500,1000,20} ;

    max_elems = read_accts (acctnum, balance, 100);
    num_elems = read_accts (acctnum, balance, 100);

    do {
    menu();
    cout << "Which banking transaction would you like to use? Enter Q to quit";
    cout << " the transaction " << endl;
    cin >> answer;
    if (answer == 'W') withdrawal(acct num, balance, num_elems);
    if (answer == 'D') deposit(acctnum , balance, num_elems);

    }while ((answer != 'Q') && (answer != 'q'));

    system ("pause");
    return 0;

    }

    // Function: read_accts
    // Input:
    // account numbers and their current balances
    // Process:
    // reads in the account number and its balance
    // Output:
    // prints the account number and its balance

    //Function to read in the account numbers and their balances
    int read_accts (int acctnumarray [], double balancearray [], int maxelems)
    {
    int a, elemcount = 0;
    double balance;
    for (a = 0; a <=6; a++){

    // declare and open input file
    // fstream infile("c:\\Dev-Cpp\\bankprogin put.txt");
    // ifstream infile(“con”); //un-comment for debugging

    cout << "The account number is " << acctnumarray[a];
    cout << "and its balance is " << balancearray[a] << endl;

    }

    return elemcount;


    }

    // Function: menu
    // Input:
    // none
    // Process:
    // creates a menu for the user
    // Output:
    // A menu is printed

    // Function to print the menu
    void menu()
    {
    cout << " Menu of Transactions" << endl;
    cout << " W = withdrawal" << endl;
    cout << " D = deposit" << endl;
    cout << " N = new account" << endl;
    cout << " B = balance" << endl;
    cout << " Q = quit" << endl;
    return;
    }

    // Function: Withdrawal
    // Input:
    // none
    // Process:
    // determines amount of money that the user wants to take out
    // Output:
    // the amount of money to be withdrawn

    // Function to make a withdrawal
    void withdrawal (int acctnumarray [], double balancearray [], int numelems)
    {
    int with = 0;
    int acctnum, a;

    cout << "Enter your account number: - end with EOF" << endl;
    cin >> acctnum;
    for (a = 0; a <= numelems; a++);
    if (acctnum == acctnumarray[a])
    {
    cout << "How much money would you like to withdraw?" << endl;
    cin >> with;
    }
    else if (acctnum != acctnumarray[a])
    {
    cout << "This is an invalid account number." << endl;
    }

    if (with <= balancearray[a])
    {
    cout << "Your account does not have a sufficient amounts of funds";
    cout << "to proceed with this transaction." << endl;
    }

    return;
    }

    // Function: Deposit
    // Input:
    // none
    // Process:
    // determines amount of money that the user wants to take out
    // Output:
    // the amount of money to be withdrawn

    //Function to make a deposit
    void deposit (int acctnumarray [], double balancearray [], int numelems)
    {
    int dep = 0;
    int acctnum, a;

    cout << "Enter your account number:" << endl;
    cin >> acctnum;
    for (a = 0; a <= numelems; a++);{
    cout << "How much money would you like to deposit?" << endl;
    cin >> dep;
    if (acctnum != acctnumarray[a]);
    cout << "This account does not exist." << endl;

    }
    return;
    }

    // Function: balance
    // Input:
    // none
    // Process:
    // determines amount of money that the user has left in their account
    // Output:
    // the amount of money to be withdrawn

    //Function to tell you how much money is in your account
    //void balance (int acctnumarray [], double balancearray [], int numelems)
    //{
    //}

    Comment

    Working...