Why won't arr as a variable work?

So for some reason whenever I try to compile this an error message shows near arr on line 72. I could use any help I could get. Thanks.


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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//Assignment 7
#include<iostream>
using namespace std;
void read_3_arrays(int r1[],int r2[],int r3[],int k);
void print_1_array(int nums[],int k);
void make_new_array(int r1[],int r2[],int r3[],int k,int sum[]);
void sort_1_array(int r[],int k);
void print_2nd_largest_and_smallest(int r[],int k);
void closest(int r[],int v, int k);
int main()
{
    int n,q=16,i;
    
    cout<<"How big is the array?"<<endl;
    cin>>n;
    
    
    int round1[n+25],round2[n+25],round3[n+25];
    int sots[n+25];
    int smallest, pos, arr ,chosen;
    
    
    read_3_arrays(round1,round2,round3,n);
    
    cout<<" "<<endl; 
    
    cout<<"Round 1."<<endl;
    print_1_array(round1,n);
    cout<<" "<<endl;
    
    cout<<"Round 2."<<endl;  
    print_1_array(round2,n);
    cout<<" "<<endl;
    
    cout<<"Round 3."<<endl;
    print_1_array(round3,n);
    cout<<" "<<endl; 
       
    make_new_array(round1,round2,round3,n,sots);
    
    
    
    sort_1_array(round1,n);  
    cout<<"Here is the Round 1 array in sorted order."<<endl;
    print_1_array(round1,n);
    print_2nd_largest_and_smallest(round1, n);
    cout<<endl;
    
    sort_1_array(round2,n);  
    cout<<"Here is the Round 2 array in sorted order."<<endl;
    print_1_array(round2,n);
    print_2nd_largest_and_smallest(round2, n);
    cout<<endl;
    
    sort_1_array(round3,n);  
    cout<<"Here is the Round 3 array in sorted order."<<endl;
    print_1_array(round3,n);
    print_2nd_largest_and_smallest(round3, n);
    cout<<endl;
    
    sort_1_array(sots,n);  
    cout<<"Here is the SumofThescores array in sorted order."<<endl;
    print_1_array(sots,n);
    print_2nd_largest_and_smallest(sots, n);
    cout<<endl;
    
    
    
        for(i=1;1<=q;i++)
    {
        cout<<"Choose an Array"<<endl;
        cin>>arr>>endl;
        cout<<"Choose a number"<<endl;
        cin>>chosen_number>>endl;
        
        if(arr==1)
                closest(round1,chosen,n);
                
        if(arr==2)
                closest(round2,chosen,n);
                
        if(arr==3)
                closest(round3,chosen,n);
                
        if(arr==4)
                closest(sots,chosen,n);
    
    
    
    }

    
    system("Pause");
}


///////////////////////////////////////////////////////////////////////////////
//Functions
///////////////////////////////////////////////////////////////////////////////


//Reads info into the arrays: round 1, 2, and 3.
void read_3_arrays(int r1[],int r2[],int r3[],int k)
{
    int lc;
    for(lc=1;lc<=k;lc++)
    {
    
        cout<<"Enter your three rounds"<<endl;
        cin>>r1[lc-1];
        cin>>r2[lc-1];
        cin>>r3[lc-1];
        
        cout<<"Your scores for the 3 rounds were;"<<endl;
        cout<<r1[lc-1]<<endl;
        cout<<r2[lc-1]<<endl;
        cout<<r3[lc-1]<<endl;
        
    }
    
    return;
}

//Prints the arrays on a 6 space grid.
void print_1_array(int nums[],int k)
{
     int lc;
     
     for(lc=1;lc<=k;lc++)
     {
          if (lc%6 != 0)
          {
               cout<<nums[lc-1]<<"  ";
          }
          else
          {
               cout<<nums[lc-1]<<endl;
          }
     }     
     cout<<" "<<endl;
     
     return;
}


//Adds the sum of the elements to another array. 
void make_new_array(int r1[],int r2[],int r3[],int k,int sum[])
{
     
     int lc;
     for(lc=1;lc<=k;lc++)
     {
          sum[lc-1]=r1[lc-1]+r2[lc-1]+r3[lc-1];
          
          
     }
     return;
}


//Sorts the numbers in an array into ascending order.
void sort_1_array(int r[],int k)
{
    int temp, lc, other;
    
    for(lc=1;lc<=k;lc++)
    {
        for(other=1;other<=k;other++)
        {
                if(r[lc-1]<r[other-1])
                {
                temp=r[lc-1];
                r[lc-1]=r[other-1];
                r[other-1]=temp;
                }
        }
    }

    
} 

void print_2nd_largest_and_smallest(int r[],int k)
{
    cout<<"The largest number is "<<r[k-1]<<endl;
    cout<<"The second largest number is "<<r[k-2]<<endl;
    cout<<"The smallest number is "<<r[0]<<endl;
    cout<<"The second smallest number is "<<r[1]<<endl;
}

void closest(int r[],int v, int k)
{

    int lc;
    
    if(v<r[0])
        cout<<"The lowest element, which is "<<r[0]<<" is the closest to the number you chose, which was "<<v<<"."<<endl;
    if(v>r[k])
        cout<<"The highest element, which is "<<r[k]<<" is the closest to the number you chose, which was "<<v<<"."<<endl;
        
    for(lc=1;lc<=k;lc++)
    {
        if(v==r[lc-1])
            cout<<"The number you chose, which is "<<v<<", is in the array at position "<<lc-1<<"."<<endl;
    }
    
    for(lc=1;lc<=k;lc++)
    {
        if(v>r[lc-1] && v<r[lc])
            cout<<"The number you chose, which is "<<v<<", is between the elements in position "<<lc-1<<" and "<<lc<<"."<<endl;

      }         
}
        
        
        
        
        
        
cin>>arr>>endl;
should be
cin>>arr;
closed account (o3hC5Di1)
As Peter mentioned, lines 71 -> 74 should be:

1
2
3
4
cout<<"Choose an Array"<<endl;
cin>>arr;
cout<<"Choose a number"<<endl;
cin>>chosen_number;


Also, you need to declare chosen_number and #include <stdlib> if you really must use system().

Hope that helps,
All the best,

NwN
Last edited on
cin>>arr>>endl;
Out of curiosity, because I've never seen this, what will happen here? Will this stick a newline character into the input stream, or will this just not compile?
It will not compile.
Thanks guys, this actually helped a lot. Though now I'm curious, (not that this was my original intent) but how would I put a new line character into an input? And would it matter?
Topic archived. No new replies allowed.