Under construction

Good Day, To construct an array to accept 10 integers, then display a table output with the following data,
Value(entered) Percent of total (% of Sum)
1
2
3...
I have this working so far. I need to see an example of how to get the smallest and the largest integer entered to display in this fashion.

cout: Values used range from (smallest) to (largest).

I also need an example of how to cout the values that are above the average of the sum.
cout: Values above the Average.



I may be a little confusing here if so please send along your questions.

code as follows:

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int MAX_ITEMS = 10;
float x[MAX_ITEMS];
float average;
float sum;

// Enter data.
cout << "Enter " << MAX_ITEMS << " numbers: ";
for (int i = 0; i < MAX_ITEMS; i++)
cin >> x[i];
// Compute the average value.
sum = 0.0;
for (int i = 0; i < MAX_ITEMS; i++)
sum+= x[i];
average = sum / MAX_ITEMS;
system ("cls");



// Displays the diference between each item and the average.

cout << fixed << showpoint << setprecision (2) << endl;
cout << setw(4) << " Value " << setw(8) << "Percent of Total"
<< endl;
for (int i= 0; i < MAX_ITEMS; i++)
cout << setw(4) << x[i] << setw(8)
<< setw(14) << (x[i] / sum) << endl << endl;
cout << "Values used range from " << x[0] << "to" << x[9] << endl << endl;
cout << " The average of the Ten values = " << average << endl << endl;

system ("pause");

return 0;


Thank You
Last edited on
You'll want to make 2 loops, to check every number in the Array with every other number (apart from itself).

Then what you can do is check how many times one number is greater than every other number. Store how many times it is greater and then assign that number to the location in the array defined by how many times it was greater.

If two numbers are the same however it will cause a problem.
Here is the attempt to get the max/min of this array and it says I have not identified i on 32 and 33, where have I made an error, \sorry still learning this.



#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
const int MAX_ITEMS = 10;
float x[MAX_ITEMS];
float average;
float sum;
float max, min;

// Enter data.
cout << "Enter " << MAX_ITEMS << " numbers: ";
for (int i = 0; i < MAX_ITEMS; i++)
cin >> x[i];

// Compute the average value.
sum = 0.0;
for (int i = 0; i < MAX_ITEMS; i++)
sum+= x[i];
average = sum / MAX_ITEMS;

// define max, min variables
max = x[0];
min = x[0];

// search the array for max, min

for (int i = 0; i < MAX_ITEMS; i++)
if (x[i] < min)
min = x[i];
if (x[i] > max)
max = x[i];

system ("cls");



// Displays the diference between each item and the average.

cout << fixed << showpoint << setprecision (2) << endl;
cout << setw(4) << " Value " << setw(8) << "Percent of Total"
<< endl;
for (int i= 0; i < MAX_ITEMS; i++)
cout << setw(4) << x[i] << setw(8)
<< setw(14) << (x[i] / sum) << endl << endl;
cout << "Values used range from " << min << "to" << max << endl << endl;
cout << " The average of the Ten values = " << average << endl << endl;

system ("pause");
return (0);

}
Last edited on
Topic archived. No new replies allowed.