Thread: moving from one array adress to another

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

    Exclamation moving from one array adress to another

    I have code that is giving me grief

    you have a number of numbers
    find one specific one in the list
    delete it
    move the rest of the list up so as to free the memory space in the array and not mess your sort up, instead of putting zero place holders

    i have included the code
    it is menu selection number 2

    i know that there are other things wrong wiith it but can for the most part fix the rest, can not seem to get the loop to make this code keep moving one after another appropriately
    any help appreciated

    thanks

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    This forum much prefers that people post the code directly into the post rather than in an attachment. Also, only post the code necessary to answer the question (For instance, only "menu selection #2"). Quickly glancing at your code, I see several things wrong with the syntax, for instance
    Code:
    result = find_account(account, total, target);
            if (result == -1)
                cout << target << " is not on the list.\n";
            else
                balance[result] = balance[result]-withdrawal;
                cout << "Your new balance for " << account[result]
                     << " is " << balance[result];
    Without braces, that output statement is not in the else structure, which means you'll be trying to access balance[-1] (and later account[-1] if your program could possibly get to it) if find_account() returns -1. Obviously this will make your program crash. You do this several times in your program.

    Also, you really should consider revising your function names. search_account_number2 and search_account_number3 are not good identifiers.
    Last edited by SlyMaelstrom; 11-10-2006 at 05:31 PM.
    Sent from my iPadŽ

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >I have code that is giving me grief
    This is the same program from your other thread. If you have further questions, please keep them to that thread.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 02:37 PM
  3. 2d array question
    By gmanUK in forum C Programming
    Replies: 2
    Last Post: 04-21-2006, 12:20 PM
  4. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  5. Moving values in an array
    By venomgts550 in forum C++ Programming
    Replies: 1
    Last Post: 11-24-2001, 06:41 PM