Answer:
- #include <iostream>
- using namespace std;
- int main()
- {
- // declare and initialize popcorn name array
- string popcorn_name[7] = {"plain", "butter", "caramel", "cheese", "chocolate", "turtle", "zebra"};
- // declare and initialize sales array with 7 elements
- int sales[7];
-
- // A loop to prompt user to enter sales for each popcorn
- for(int i=0; i < 7; i++){
- cout<<"Enter number of sales for " + popcorn_name[i] + " :";
- cin>>sales[i];
- }
-
- // Find maximum sales
- int max = sales[0];
- int maxIndex = 0;
- for(int j=1; j < 7; j++){
- if(max < sales[j]){
- max = sales[j];
- maxIndex = j;
- }
- }
-
- // Find minimum sales
- int min = sales[0];
- int minIndex = 0;
- for(int k=1; k < 7; k++){
- if(min > sales[k]){
- min = sales[k];
- minIndex = k;
- }
- }
-
- // Print popcorn name and sales
- for(int l=0; l < 7 ; l++){
- cout<<popcorn_name[l]<<"\\";
- cout<<"Sales: "<< sales[l]<<"\\\\";
- }
-
- // Print popcorn name with maximum and minimum sales
- cout<<"Highest selling: "<< popcorn_name[maxIndex]<<"\\";
- cout<<"Lowest selling: "<<popcorn_name[minIndex]<<"\\";
- return 0;
- }
Step-by-step explanation:
Create two arrays to hold the list of popcorn name and their sales (Line 5-8). Next prompt user to input the sales for each popcorn (Line 10-14). Get the maximum sales of the popcorn (Line 17-24) and minimum sales (Line 27-34). Print the popcorn name and sales (Line 37-40) and the popcorn name with highest and lowest selling (Line 43-44).