You will write a console program that will meet the following requirements: Create a console program where you will implement variables that are needed for this program and will implement the code within Main. Create an array that stores 10 prices. Prompt the user to enter the 10 values as currency. Access the array elements and display a sum of the 10 values. Display all of the entered values less than $5.00. Calculate the average of the 10 values. Display the average of the entered values and the entered values higher than the average. You should format your output to look something like the following: This will require some analysis of the problem before coding is accomplished. Enter price 1 1.11 Enter price 2 2.22 Enter price 3 3.33 Enter price 4 4.44 Enter price 5 5.55 Enter price 6 6.66 Enter price 7 7.77 Enter price 8 8.88 Enter price 9 9.99 Enter price 10 10.10 The sum of the values entered is: $60.05 Prices less than $5.00:$1.11 $2.22 $3.33 $4.44 Prices higher than average $6.01$6.66 $7.77 $8.88 $9.99 $10.10

Respuesta :

Answer:

The solution code is written in C++.

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. int main()
  5. {
  6.    int i;
  7.    double prices[10];
  8.    double sum = 0;
  9.    string less5 = "";
  10.    double average;
  11.    string higherAVG = "";
  12.    
  13.    for(i=0; i < 10; i++){
  14.        cout<<"Enter price "<< (i+1) <<": ";
  15.        cin>>prices[i];
  16.    }
  17.    
  18.    for(i=0; i <10; i++){
  19.        sum += prices[i];
  20.        
  21.        if(prices[i] < 5){
  22.            less5 += "$"+ std::to_string(prices[i]) + " ";
  23.        }
  24.    }
  25.    
  26.    cout<<"The sum of the values entered is: $"<<sum <<"\n";
  27.    cout<<"Prices less than $5.00:" + less5<<"\n";
  28.    
  29.    average = sum / 10;
  30.    
  31.    for(i=0; i <10; i++){
  32.        if(prices[i] > average){
  33.            higherAVG += "$" + std::to_string(prices[i]) + " ";  
  34.        }
  35.    }
  36.    
  37.    cout<<"Average values: $" + std::to_string(average) + "\n";
  38.    cout<<"Prices higher than average" + higherAVG + "\n";
  39.    
  40.    return 0;
  41. }

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).