so I have this simple program here and my instructor is asking for the following edits, and I can't see it:
Sorry, you are missing the point. Since all of your functions are using indexing from 1 to n, where n can be 100, you never use the element with index zero of the array. That means that the maximum number of values you will use in the array is 99. If the user really wants to enter 100 values, your solution then won’t work.
Can you fix your solution again?
#include <iostream>
using namespace std;
int readnums(int v[]);
void findmaxmin(int v[],int n,int &mi,int &ma);
int findmidsum(int v[],int n,int mi,int ma);
int main()
{
const int ARRAYVALUE=100;
int v[ARRAYVALUE];
int n=readnums(v),mi,ma;
findmaxmin(v,n,mi,ma);
cout<<"Max= "<<ma<<endl;
cout<<"Min= "<<mi<<endl;
cout<<"Middle sum= "<<findmidsum(v,n,mi,ma)<<endl;
}
int readnums(int v[])
{
cout<<"How many numbers to enter: ";
int n=0;
cin>>n;
for(int a=1;a<=n;a++)
{
cout<<"Enter no. "<<a<<": ";
cin>>v[a];
}
return n;
}
void findmaxmin(int v[],int n,int &mi,int &ma)
{
ma=v[1];
mi=v[1];
for(int a=1;a<=n;a++)
{
if(mi>v[a])mi=v[a];
if(ma<v[a])ma=v[a];
}
}
int findmidsum(int v[],int n,int mi,int ma)
{
int s=0;
for(int a=1;a<=n;a++)
if(v[a]!=mi && v[a]!=ma)
s+=v[a];
return s;
}
[0, 99]?assert()to check the parameters passed to the function.a=1toa<=niterate froma=0toa<n.