1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <conio.h>
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
using std::setprecision;
using std::fixed;
int main()
{
const int priceSize = 20;
const int under5Size = 20;
float prices[ priceSize ] = { 2.34, 7.89, 1.34, 9.99, 3.24, 4.25, 5.68, 1.21, 8.45, 9.85, 2.75, 3.68, 5.68, 8.26, 9.10, 1.02, 6.30, 5.32, 7.99, 2.35 };
float under5[ under5Size ] = { 0 };
float total = 0;
float average;
for ( int i = 0; i < priceSize; i++ ){
total += prices[ i ];
}
for ( int j = 0; j < priceSize; j++){
if(prices[ j ] < 5)
{
int k = 0;
under5[ k ] = prices[ j ];
k++;
}
cout << under5[ j ] << endl;
}
average = total / 20;
cout << "Total of prices: " << total << endl;
cout << endl << "The average of all the prices is: "<< setprecision(2) << fixed << average << endl;
char pause = getchar(); // program pauses before ending
getchar();
return 0;
}
|