Thread: help with this code please

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    38

    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
    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()
    {
    
          Menu_Selection();
    
    
    
      cout << "\nPress <ENTER> to continue.\n";
      fflush(stdin);
      cin.get();
    }
    /*------------------------------------------------------------------------------
            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;
    
         do
         {
              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;
                         break;
                     case 2:
                          cout << "works";
                        //code to display deletion of an existing account.
                         break;
                    case 3:
                        cout << "works";
                        //code to display deposit entry.
                         break;
                    case 4:
                        cout << "works";
                         //code to display withdrawel deduction.
                         break;
                    case 5:
                         print_all_accounts(account,balance,total);
                         cout << endl;
                         break;
                    case 6:
                         cout << "works";
                         //code to display grand total of all available accounts.
                         break;
                    case 7:
                        cout << "End of Program.\n";
                        break;
                    default:
                    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)
            {
             total++;
    
            }
        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];
                     i--;
                    }
             account[total]=account[result];
             balance[total]=account[result];
             total++;
             }
    }
    
     /*------------------------------------------------------------------------------
    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;
            else
                index++;
    
        if (found)
            return index;
        else
            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:
    Build
    [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
    Sincerely
    Jessie

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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
    Location
    The edge of the known universe
    Posts
    39,659
    > 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
    Location
    Canada
    Posts
    8,057
    Code:
    fflush(stdin);
    Don't do this -- see the FAQ.
    dwk

    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: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    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