Answer:
The solution code is written in C++.
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- int i;
- double prices[10];
- double sum = 0;
- string less5 = "";
- double average;
- string higherAVG = "";
-
- for(i=0; i < 10; i++){
- cout<<"Enter price "<< (i+1) <<": ";
- cin>>prices[i];
- }
-
- for(i=0; i <10; i++){
- sum += prices[i];
-
- if(prices[i] < 5){
- less5 += "$"+ std::to_string(prices[i]) + " ";
- }
- }
-
- cout<<"The sum of the values entered is: $"<<sum <<"\n";
- cout<<"Prices less than $5.00:" + less5<<"\n";
-
- average = sum / 10;
-
- for(i=0; i <10; i++){
- if(prices[i] > average){
- higherAVG += "$" + std::to_string(prices[i]) + " ";
- }
- }
-
- cout<<"Average values: $" + std::to_string(average) + "\n";
- cout<<"Prices higher than average" + higherAVG + "\n";
-
- return 0;
- }
Explanation:
Firstly, we declare all the required variables (Line 7-12).
We use the first for-loop to prompt user to input 10 values into the prices array (Line 14-17).
Next, we create second for-loop to sum up all the values held by the prices array and at the same time generate the output string for those value lower than 5 (Line 19-25).
Next, we calculate the average (Line 30) and create another for-loop to generate the output string of those value higher than average (Line 32-35).
At last, we can display all the required output to console terminal (Line 27-28 and Line 38-39).