im trying to write a program that reads an array on non negative numbers and outputs the orginal array, then finds the max/2 and than out puts an modfied array that consist of all the numbers that are greater than the array max/2
You are on right track, but you are not filling the numbers in the array.
The code
1 2 3 4 5 6 7 8 9 10 11 12 13
int i = 0;
while (i != -100 && num_elements < ARRAY_SIZE)
{
if(i > - 1)
{
num_elements++;
cin >> i;
}
else
{
cin >> i;
}
}
can be written as
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
while( (num_elements < ARRAY_SIZE) && (cin >> a[num_elements]) && (-100 != a[num_elements]) )
{
if( a[num_elements] > 0)
{
//Entered number was positive increment count so that next number
// is input in next element
num_elements++;
}
else
{
//Entered number was negative, don't increment the count so that the next
// number will overwrite currently input negative number
cout << "Enter positive numbers only" << endl;
}
}
Then for printing elements of array, instead of cout << endl << "Original List (" << num_elements << " values): " << endl;
you need loop something like
1 2 3 4 5
cout << "Original list" << endl;
for(auto i& : a)
{
cout << i << endl;
}
if(a[j] > max) needs to be if((a[j]/2.0) > max)
then again for printing modified list you need loop similar to loop above