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]<<", ";
}
}
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();
^