How to copy one array to another incrementally

My goal of this function is to incrementally load packages(integer elements) onto each truck loadspace (the columns of the 2D array with 20 empty elements) while keeping the sum of packages (integer elements) < 1000. I have attempted to use iterators, if/else statements, while, and do-while loops. I'm honestly having a hard time with this. Thank you ahead of time for any and all help. The program compiles also

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  void loadTrucks(int** trucks, int* packages, int numTrucks, int numPackages)
{
    int temp = 0;
    int sum = 0;

    for(int i = 0; i < numTrucks; i++){     //This loop traverses the trucks
        for(int j = 0; j < 20; j++){       //This loop traverses the load space
            for(int k = 0; k < numPackages; k++){ //This loop traverses the packages
                while(sum < 1000){
                    temp = packages[k];
                    packages[k] = trucks[i][j];
                    trucks[i][j] = temp++;
                    sum += trucks[i][j];
                };
            }
        }
    }
}
Last edited on
Please use code tags so we can refer to specific line numbers.

What is your question? If the code doesn't compile then please provide the exact compilation error. If it doesn't work then please provide the input, expected output, and what the actual output is.
Please use code tags. If you have a question, please ask it.
Topic archived. No new replies allowed.