How do I execute three separate functions in an array?

How do I go about changing this array so that there are three functions in it. The output is right but I need to write the code so that I am using function. Is it referring to void functions, passing arrays to functions. I am confused on what is being asked and I am pretty new to coding. This is the question.

Write a C++ program that declares an integer array of size 10, then uses three separate functions, one to do each of the following:

Ask user to enter 10 numbers for the array
Print out the array (all the array elements)
Find the maximum value of the array and return it to be printed in main()"


This is the code I have made so far.

#include<iostream>
using namespace std;



int main()

{

int n;

int array[10];

cout<<"enter 10 numbers:"<<endl;

for(int i=0;i<10;i++)

cin>>array[i];

cout<<"Print"<<endl;

for(int i=0;i<10;i++)

cout<<array[i]<<" "<<endl;



int max=0;

for(int i=0;i<10;i++)
{
if (array[i]>max);
max=array[i];
}

cout<<"Max"<<endl<<max;

return 0;

}
1
2
3
4
5
6
7
8
9
10
11
12
void input(int v[], int size);
void output(int v[], int size);
int maximum(int v[], int size);

int main(){
   const int n = 10;
   int array[n];

   input(array, n);
   output(array, n);
   std::cout << maximum(array, n) << '\n';
}
fill the blanks
Thanks so much ne555. There is only one other issue I have that I am trying to solve. I am getting this message when I try to compile the code.

undefined reference to `input(int*, int)'
undefined reference to `output(int*, int)'
undefined reference to `maximum(int*, int)'
collect2.exe: error: ld returned 1 exit status


This is the code that I tried to fill in after your previous help.
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
#include<iostream>
using namespace std;

void input(int array[], int size);
void output(int array[], int size);
int maximum(int array[], int size);

int main()

{
	int array[10];
	input(array, 10);
	output(array, 10);
	std::cout << maximum(array, 10) << '\n';
	const int n=10;


	
	
	void input(int array[], int size);
	{
	cout<<"enter 10 numbers:"<<endl;
	
		for(int i=0;i<10;i++)
		{
		cin>>array[i];
	
		cout<<"Print"<<endl;
		}
	{
	
	void output(int array[], int size);
	{
		for(int i=0;i<10;i++)
		{
		cout<<array[i]<<" "<<endl;
		}
	{
	
	int maximum(int array[], int size);
	{
		int max=0;

		for(int i=0;i<10;i++)
		{
		if (array[i]>max);
		max=array[i];
		}

		cout<<"Max"<<endl<<max;
		}
	return 0;

}
Hi,

Some suggestions:

Try compiling this with cpp.sh (press the gear icon top right of your code). Turn on all warning check boxes. Warnings are your friend.

Answer these questions:

What does a function definition look like?

How does a function definition differ from a function declaration? You have the function declarations on lines 4 to 6. Hint there is one piece of punctuation at the end of a line.

Where does a function definition go in the file?

There is also a similar problem on line 46.
Thanks TheIdeasMan I finally got it to work. I always thought the syntax didn't make sense, but you helped me make sense of it.

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

void input(int array[], int size);
void output(int [], int size);
int maximum(int [], int size);

int main()

{
   const int n = 10;
	int array[n];
	input(array,10);
	output(array,10);
	


}
	
	void input(int array[], int size)
	{
	cout<<"enter 10 numbers:"<<endl;
	
		for(int i=0;i<10;i++)
		{
		cin>>array[i];
	
		}
	}
	
	void output(int array[], int size)
	{
	    cout<<"Print"<<endl;
		for(int i=0;i<10;i++)
		{
		cout<<array[i]<<" "<<endl;
		}
	}
	
	int maximum(int array[], int size)
	{
		int max=0;

		for(int i=0;i<10;i++)
		{
		if (array[i]>max)
		max=array[i];
		}

		cout<<"Max"<<endl<<max;
		int i(); 
		return 0;
	}


indent your code.
¿what's the purpose of line 51?
¿are you sure that 0 is a good starting value for `max'?
you never call the maximum() function
¿why do you think the functions ask for a `size' parameter?
Last edited on
Topic archived. No new replies allowed.