(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()
(what I have tried)
#include <iostream>
using namespace std;
void getMax( int );
int main (){
int day[10];
cout << " Please enter 10 numbers: ";
for (int i=0; i<10; i++)
cin >> day[i];
max = getMax(day[i]);
return 0;
}
void getMax( int day[])
{
int max;
for (int i=0; i<10; i++)
max = day[i];
#include <iostream>
usingnamespace std;
void getMax( int );
int main (){
int day[10];
cout << " Please enter 10 numbers: ";
for ( int i=0; i<10; i++ )
cin >> day[i];
max = getMax( day[i] );
return 0;
}
void getMax( int day[] )
{
int max;
for ( int i=0; i<10; i++ )
max = day[i];
return;
}
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 should be the outline of the program you start with.
Copy/paste the imperative statements as comments into your program source.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Ask user to enter 10 numbers for the array
void inputArray(int arr[10]) {
}
// Print out the array (all the array elements)
void printArray(int arr[10]) {
}
// Find the maximum value of the array and return it to be printed in main()
int findMaxInArray(int arr[10]) {
int max = 0;
return max;
}
int main ( ) {
// declares an integer array of size 10
int array[10] = { 0 };
}
It doesn't do anything, but at least it compiles and is a foundation on which to build.
The next step is fill out ONE of the functions. I would suggest printArray first, because having that working makes it so much easier to see if inputArray works in the next step.
1 2 3 4 5
int main ( ) {
// declares an integer array of size 10
int array[10] = { 0 };
printArray(array);
}
MAKE sure this
a) compiles
b) works
before rushing off to implement the next function.
The point of all this is to make your edit / compile / test cycles short enough that you're not totally confused by the outcome.