Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m still not getting the correct output for this program here is the program a

ID: 3623030 • Letter: I

Question

I'm still not getting the correct output for this program here is the program and its output.

/* 2170_3_3.cc
Problem description: Write a program that reads an unspecified number (no more than 20) of
positive integers, finds, and prints the maximal and minimal values using an array.
The input ends with the 0. For example, if you entered 1, 100, 20, 2, and 0,
the program should print 100 and 1.

This exercise is for learning the array concept with a proper use of reference and value parameters.
*/

#include
using namespace std;

//function prototype of a function returning max & min values of an integer array
void getBoundary(int[],int,int&,int&);
int main( )
{
const int CAPACITY = 20; //array capacity
int value[CAPACITY];
int max, min; // maximum and minimum values stored in the array value
int intNum;

// read values from the input until it reads 0 and store the values in the array except 0
cout<<"Enter a number, 0 to exit: ";
cin>>value[intNum];
while(value[intNum]!=0&&intNum<20)
{intNum++;
cout<<"Enter a number, 0 to exit: ";
cin>>value[intNum];
}
//call the function to get max and min value in the array value
getBoundary(value,intNum, min, max);

cout << intNum <<" integers have been read." << endl
<< "The maximal value is " << max << endl
<< "The minimal value is " << min << endl;

return 0;
}

//Implementation of the void function getBoundary
// function returns max & min values of an integer array as reference parameter

void getBoundary ( int a[],int n,int& min,int& max )

Write the function body of getBoundary


{
int i;
min=a[0];
max=a[0];
for(i=1;i if(a[i] min=a[i];
else
if(a[i]>max)
max=a[i];
}

here is the output:

Explanation / Answer

please rate-thanks

intNum was never set to 0

#include <iostream>
using namespace std;

//function prototype of a function returning max & min values of an integer array
void getBoundary(int[],int,int&,int&);
int main( )
{
const int CAPACITY = 20; //array capacity
int value[CAPACITY];
int max, min; // maximum and minimum values stored in the array value
int intNum;
intNum=0;
// read values from the input until it reads 0 and store the values in the array except 0
cout<<"Enter a number, 0 to exit: ";
cin>>value[intNum];
while(value[intNum]!=0&&intNum<20)
{intNum++;
cout<<"Enter a number, 0 to exit: ";
cin>>value[intNum];
}
//call the function to get max and min value in the array value
getBoundary(value,intNum, min, max);

cout << intNum <<" integers have been read." << endl
<< "The maximal value is " << max << endl
<< "The minimal value is " << min << endl;
system("pause");
return 0;
}

//Implementation of the void function getBoundary
// function returns max & min values of an integer array as reference parameter

void getBoundary ( int a[],int n,int& min,int& max )

//Write the function body of getBoundary


{
int i;
min=a[0];
max=a[0];
for(i=1;i<n;i++)
if(a[i]<min)
     min=a[i];
else
if(a[i]>max)
max=a[i];
}