Why doesn't this code work?

Can anyone help please?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <cstdlib>

using namespace std;

void start (int boxes [10]);
void move (int squares [10], int x, int y, int z);
void add (int arr [10], int first, int last);
void print (int arr [10]);

int main ()
{
    int my_arr [10];
    
    cout << "The original array is:\n";
    print (my_arr);
    
    start (my_arr);
    cout << "\n\nThe array after start is:\n";
    print (my_arr);
    
    move (my_arr, 2, 4, 6);
    cout << "\n\nThe array after move is:\n";
    print (my_arr);
    
    add (my_arr, 3, 7);
    cout << "\n\nThe array after add is:\n";
    print (my_arr);
    
    cout << "\n\n";
    system ("PAUSE");
    return EXIT_SUCCESS;
}

 
void start (int boxes [10])
{
     int index, count;
     
     count = 17;
     for (index = 0; index < 10; index++)
     {
         boxes [index] = count;
         count--;
     }
}

void move (int squares [10], int x, int y, int z)
{
     int temp;
     
     temp = squares [x];
     squares [x] = squares [y];
     squares [z] = squares [y];
     squares [y] = temp;
}

void add (int arr [10], int first, int last)
{
     int m;
     
     for (m = first; m <= last; m++)
         arr [m]++;
}

void print (int arr [10])
{
     int z;
     
     for (z = 0; z < 10; z++)
         cout << z << " ";
}
Double check your "print()" function OP. You're not even using the array that you pass in.
Define "does not work".
The function print is supposed to print each element of the array but it doesn't.. I don't know it's for a school project and honestly I have no idea what i'm doing....Any help would be appreciated
The function print is supposed to print each element of the array...

Then why are you telling it to print the variable 'z'?
Ohh okay i fixed it i changed it to arr[z] but now it won't show the original array and it's showing random values instead
What is the original array supposed to be? You don't intialize it before your first call to "print()" and I'm not sure what "start()" is meant to do, why does it arbitrarily go from 17 to 7?
it works fine in cpp.sh...
I fixed it now and everything works thank you for the help!
if it is fixed close the topic unless there's something else...
Topic archived. No new replies allowed.