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];
}
void input(int v[], int size);
void output(int v[], int size);
int maximum(int v[], int size);
int main(){
constint n = 10;
int array[n];
input(array, n);
output(array, n);
std::cout << maximum(array, n) << '\n';
}
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.
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.
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?