Array question please help

Answering the following problem regarding arrays
My code so far is below. I am having a trouble compiling and dont know what to fix
Any help would be greatly appreciated
Thanks

Write a program called array.cpp which prompts and reads a list of positive numbers (ints)
into an array, prints the array, finds the minimum value in the array, subtracts the minimum
value to each array number and then prints the minimum number and the modified array. The
input list is terminated by a 0. The program should have a function read_list() for reading in a
list of values, a function print_array which prints each array element, a function find_min() for
finding minimum number in the array, and a function array_scale() which multiplies a number
with each element of the array.


#include <iostream>
#include <cmath>

using namespace std;
void read_list(int array[], int & num_elements, const int ARRAY_SIZE);
void print_array(const int array[], const int num_elements);
int find_min(const int array[], const int num_elements);
void array_scale(const int x, int array[], const int num_elements);

int main()
{
const int ARRAY_SIZE(25);
int array[ARRAY_SIZE];
int num_elements(0);
int x(0);
read_list(array[ARRAY_SIZE],num_elements,ARRAY_SIZE);
print_array(array[ARRAY_SIZE], num_elements);
find_min(array[ARRAY_SIZE], num_elements);
array_scale(x, array[ARRAY_SIZE], num_elements);

return 0;
}
void read_list(int array[], int & num_elements, const int ARRAY_SIZE){
cout<<"Enter positive numbers (ints) terminated by 0";
cin>> array[0];
for(int i =1; i <ARRAY_SIZE-1; i++){
cin>> array[i];
num_elements = num_elements +1;
}
}
void print_array(int array[],int num_elements){
cout<<"Before list: ("<<num_elements<<" numbers):"<<endl;
for (int i =0; i<num_elements; i++){
cout<<array[i]<<", ";
}
cout<<"."<<endl;
}
int find_min(int array, int num_elements){
int array_min(0);
if (num_elements < 1){
return(0);
}
array_min = array[0];
for(int i =1; i<num_elements; i++)
{
if (array[i] < array_min)
{
array_min = array[i];
}

}
return(array_min);
}
void array_scale(int x, int array[], int num_elements){
for(int i =0; i<num_elements; i++)
{
array[i] = array[i] * x;
}
for(int i =0; i<num_elements; i++){
cout<<array[i]<<", ";
}
}
It will be more helpful to post your exact error messages.
main.cpp:15:13: error: 'array' was not declared in this scope
read_list(array[],num_elements);
^
main.cpp:15:19: error: expected primary-expression before ']' token
read_list(array[],num_elements);
^
main.cpp:15:21: error: 'num_elements' was not declared in this scope
read_list(array[],num_elements);
^
main.cpp:16:17: error: too few arguments to function 'void print_array(int*, int)'
print_array();
^

closed account (48T7M4Gy)
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
#include <iostream>
#include <cmath>

using namespace std;
void read_list(int array[], int & num_elements, const int ARRAY_SIZE);
void print_array(const int array[], const int num_elements);
int find_min(const int array[], const int num_elements);
void array_scale(const int x, int array[], const int num_elements);

int main()
{
const int ARRAY_SIZE(25);
int array[ARRAY_SIZE];
int num_elements(0);
int x(0);
read_list(array[ARRAY_SIZE],num_elements,ARRAY_SIZE);
print_array(array[ARRAY_SIZE], num_elements);
find_min(array[ARRAY_SIZE], num_elements);
array_scale(x, array[ARRAY_SIZE], num_elements);

return 0;
}
void read_list(int array[], int & num_elements, const int ARRAY_SIZE){
cout<<"Enter positive numbers (ints) terminated by 0";
cin>> array[0];
for(int i =1; i <ARRAY_SIZE-1; i++){
cin>> array[i];
num_elements = num_elements +1;
}
}
void print_array(int array[],int num_elements){
cout<<"Before list: ("<<num_elements<<" numbers):"<<endl;
for (int i =0; i<num_elements; i++){
cout<<array[i]<<", ";
}
cout<<"."<<endl;
}
int find_min(int array, int num_elements){
int array_min(0);
if (num_elements < 1){
return(0);
}
array_min = array[0];
for(int i =1; i<num_elements; i++)
{
if (array[i] < array_min)
{
array_min = array[i];
}

}
return(array_min);
}
void array_scale(int x, int array[], int num_elements){
for(int i =0; i<num_elements; i++)
{
array[i] = array[i] * x;
}
for(int i =0; i<num_elements; i++){
cout<<array[i]<<", ";
}
}
Topic archived. No new replies allowed.