Thread: problem with a for loop (emergancy)

  1. #1
    darkdaysx
    Guest

    Exclamation problem with a for loop (emergancy)

    This project is due in a few hours (midnight tonight)
    the only remaining problem is that this loop will not execute:

    int x = (size - sizearray - index);
    for (int g = 0; g < x; g++)
    {
    cout << "in the loop" << endl;
    newarray[g + index + sizearray] = temparray[g - sizearray + index];
    cout << newarray[g+index+sizearray] << temparray[g-sizearray+index];
    }
    cout << endl;
    cout << endl;

    please forgive all of the debugging statements.
    the program used dynamic arrays, the function this loop is in inserts an array of given size at a given index bumping the values of the origional array up. this loop is supposed to set the last few values of the array...
    any help would be much appreciated

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    int x = (size - sizearray - index);
    what sort of values will be in size, sizearray and index.
    If you end up with a negative number in x your loop will not execute
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    darkdaysx
    Guest

    Exclamation i did not think of that, but still, it didnt work

    amazingly i did not think of that, however after rewriting the loop to eliminate the negative possibility it still will not run
    this is the new loop code
    int x = (sizearray + index);
    cout << x << endl;
    for (int y = x; y < size; y++)
    {
    newarray[y] = temparray[y - sizearray];
    }

    to clear things up a little
    sizearray is the size of the array to be inserted
    index is the index at which the array will be inserted
    size is the size of the main array

  4. #4
    Unregistered
    Guest
    problem is fixed, thanks for whoever helped

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM