Thread: help with this code please

  1. #1
    Registered User
    Join Date
    Nov 2006

    help with this code please

    I have posted a few times and been grateful for the help.
    Even printed out 65 pages from a sorting link sent to me.
    However, I am having a brain clog and can not get past this piece of code.

    I am hoping that someone can help me.
    1. this is a 1st year c++ class
    2. the instructor does not want us using libraries that include functions like sort or to use classes
    3. I THINK I have the idea behind this and I have compared code that I have written that looks exactly the same and works! (like the find_sort function)

    All my errors (right now am only looking at the errors given during build) will look at logic errors once I get past the build par.
    4. all my errors that are being given are coming from the accout_sort function.

    Here is the code
      #include <iostream>
      using namespace std;
      //Prototypes -- function declarations.
      void Menu_Selection();
      void enter_accounts (int[],double[],int,int& total);
      void print_all_accounts(int[],double[],int& total);
      int find_account(int[],int&,int);
      int account_sort(int[],int& ,int);
      int check_sort(int[] , int&);
    void main()
      cout << "\nPress <ENTER> to continue.\n";
            This section of code is the initial screen after employee signs in
                    to system.  From here said employee can choose what she must
                    do with each customer being assisted.
      void Menu_Selection()
         const int NUMBER = 10;
         int account[NUMBER], total=0;
         double balance[NUMBER];
         int option;
              cout << endl
                   << "1. Add a distinct account number: \n \n"
                   << "2. Remove an existing account number: \n \n"
                   << "3. Deposit Funds into distinct account: \n \n"
                   << "4. Withdraw Funds from distinct account: \n \n"
                   << "5. View all Customer accounts and Balance: \n \n"
                   << "6. Total Funds available from All accounts: \n \n"
                   << "7. Exit program: \n \n";
              cin >> option;
              cout << endl;
              switch (option)
                    case 1:
                         enter_accounts (account,balance,NUMBER,total);
                         cout << endl;
                     case 2:
                          cout << "works";
                        //code to display deletion of an existing account.
                    case 3:
                        cout << "works";
                        //code to display deposit entry.
                    case 4:
                        cout << "works";
                         //code to display withdrawel deduction.
                    case 5:
                         cout << endl;
                    case 6:
                         cout << "works";
                         //code to display grand total of all available accounts.
                    case 7:
                        cout << "End of Program.\n";
                    cout << "Not a valid option. Please choose a valid option. \n\n";
         }while (option != 7);
     This function allows a user to add an account with its beginning balance.
            accounts are to be sorted and no to account numbers are to be the same
    void enter_accounts (int account[],double balance[],const int NUMBER, int& total)
     int result;
     int target;
     if(total >= NUMBER)
            cout <<"Maximum account capacity has been reached.\n"
                 <<"Please delete an account to continue\n";
          else if(total < NUMBER)
             cout <<"Please enter new account number.\n";
             cin >> account[total];
             cout << "Please enter opening balance ($10.00 minimum)\n";
             cin >> balance[total];
     result = check_sort(account,total);
        if(result ==0)
        else if (result ==-1)
             int next=account[total];
             int result2;
             result2 = account_sort(account,next,target);
             int i=account[next];
             while (i>=result2)
                     account[i] = account[i+1];
                     balance[i] = balance[i+1];
    This function finds an account number called and returns the target array or
    location of this particular account variable to functions for deposit to account,
    withdraw from account and delete account.
     int account_sort(int account[];int& total;int target)
        int index = 0;
        bool found = false;
        while ((!found) && (index < total))
            if (target < account[index])
                found = true;
        if (found)
            return index;
            return -1;
            This function tests to see if the array is properly sorted, if it is it
            returns a 1 if it is not it returns a 0.
    int check_sort(int account[], int& total)
      int i;
      for (i=0; i == total; i++)
         if (account[i] > account[i+1])
            return 0;
       return 1;
    This function prints all acounts listed in the "bank array" as well as thier
    corresponding balances.
    void print_all_accounts(int account[],double balance[],int& total)
      for( int i = 0; i < total ; i++ )
                    cout << "Account number " << account[i];
                    cout << " Account balance is $" << balance[i];
                    cout << endl;
    and here are the messages that I get:
    [C++ Error] assignment5test.cpp(155): E2356 Type mismatch in redeclaration of 'account_sort(int *,int &,int)'
    [C++ Error] assignment5test.cpp(24): E2344 Earlier declaration of 'account_sort(int *,int &,int)'
    [C++ Error] assignment5test.cpp(155): E2063 Illegal initialization
    [C++ Error] assignment5test.cpp(155): E2293 ) expected
    [C++ Error] assignment5test.cpp(155): E2304 Reference variable 'total' must be initialized
    [C++ Error] assignment5test.cpp(155): E2141 Declaration syntax error
    ANY help is greatly appreciated

  2. #2
    Registered User
    Join Date
    Mar 2002
    int account_sort(int account[];int& total;int target)

    Replace the semicolons with commas.
    You're only born perfect.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > void main()
    main returns int

    > for (i=0; i == total; i++)
    This probably doesn't run as many times as you would want it to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Don't do this -- see the FAQ.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM