#include <iostream>
#include <cmath>
usingnamespace std;
constint arraySize =10;
constint sentinel = 0;
int index;
int arr[arraySize]; //array as array index
int count = 0;
int sum = 0;
double median=0;
//function prototypes
int makeSortArray(constint arr[], int count);
void output(constint arr[], int count);
void revOutput (constint arr[], int count);
int main ()
{
makeSortArray(arr, count);
output(arr, count);
return 0;
}
//1. function for input
int makeSortArray (constint arr[], int count)
{
int pos = 0;
bool found = false;
int num;
cout << "Enter up to 10 positive integers, 0 to quit: \n";
cin >> num;
while(num != sentinel)
{
if (count == arraySize)
cout << "You have 10 digits, more entries will be ignored. Enter 0 to quit";
elseif (num<0)
cout << "Please enter a positive interger or 0 to quit" << endl;
else
{ // find the insert position.
while(!found&&pos<count)
{
if(arr[pos]<=num)
{
pos++;
}
else
{
found=true;
}
}
found=false;//reset the found
//move arr[pos]~arr[count-1]to arr[pos-1]~arr[count]
int i=count;
while(i>pos)
{
arr[i]=arr[i-1]; // ERROR POINTS HERE
i--;
}
arr[pos]=num;//insert the positive integer// ERROR POINTS HERE
pos=0;//reset the pos;
count++;//the number of input add one
}
cin >> num;
}
}
//2. function to output the array to screen
void output(constint arr[], int count)
{
cout << "Output Function: \n ";
for (index=0; index<arraySize; index++)
cout << arr[index] <<" " << endl;
}