array manipulation problem

whenever i run this program, it says the program has stopped working and the event name is: APPCRASH (?). I have no idea what I'm doing wrong... any help would be greatly appreciated!!

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
  #include <iostream>
using namespace std;

const int MAXSIZE = 25;
void getlist(int[], int&);
void putlist(const int[], int);
void reverse(const int[], int);
void EvenValues(const int[], int);
void GreaterThan(const int[], int);


int main ()
{
    int list [MAXSIZE];
    int num_items;
 
    getlist(list, num_items);
    
    putlist(list, num_items);
    
    reverse(list, num_items);
    
    EvenValues(list, num_items);
    
    GreaterThan(list, num_items);
    
    system("pause");
    return 0;
}
void getlist(int list[], int& num_items)
{
     int i;
     cout<<"Please enter the number of array values"<<endl;
     cin>>list[i];
     }
void putlist(const int list[], int num_items)
{
     cout<<"Array Elements"<<endl;
     for (int i=0; i<num_items; i++)
         cout<<i<<" "<<list[i]<<endl;
     }
void reverse(const int list[], int num_items)
{
     cout<<"List in Reverse Order"<<endl;
     for (int i=num_items; i>=0; i--)
         cout<<i<<" "<<list[i]<<endl;
     }
void EvenValues(const int list[], int num_items)
{
     cout<<"Even Values"<<endl;
     int i, n = list[i]%2;
     for (int i=0; i<=num_items; i++)
         if (n=0)
            cout<<i<<" "<<list[i]<<endl;
     }
void GreaterThan(const int list[], int num_items)
{
     cout<<"Greater Than"<<endl;
     for (int i=0; i = num_items-1; i++)
         if (list[i]>list[i++])
            cout<<i<<" "<<list[i]<<endl;
     }
     
On line 34 you are trying to access list[i] but i has not been initialized.
How do I initialize list[i]? I thought that's what "int list [MAXSIZE];" did. Sorry I'm new to this
You want getlist to give a value to num_items? In that case you don't even need the list in that function.
Ok, so do I change getlist to
void getlist(int list[], int& num_items)
{
int i;
cout<<"Please enter the number of array values"<<endl;
cin>> num_items;
}
?
Topic archived. No new replies allowed.