Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ Write an application to calculate retail sales. Specifications An online ret

ID: 3903948 • Letter: C

Question

c++

Write an application to calculate retail sales.

Specifications

An online retailer sells five products whose retail prices are as follows:

Product 1, $2.98

Product 2, $4.50

Product 3, $3.98

Product 4, $4.49

Product 5, $6.87

Your program should read (from the keyboard) a series of pairs of numbers as follows:

product number

quantity sold

Run your program from a simple menu with the following options

Enter products sold

Display total retail value

Exit

Your program should

allow for entry of multiple products without returning to the main menu (use a sentinel-controlled loop)

use a switch statement to determine the retail price for each product

calculate and display the quantity and total retail value of each product sold

total and display the retail value of all products sold

Explanation / Answer

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks

//Code

#include<iostream>

using namespace std;

//method to display the menu

void showMenu(){

                cout<<"1. Enter products sold"<<endl;

                cout<<"2. Display total retail value"<<endl;

                cout<<"3. Exit"<<endl;

                cout<<"Enter your choice: ";

}

int main(){

                //array storing the prices of all products

                double prices[]={2.98,4.50,3.98,4.49,6.87};

                //array storing the quantity sold for all products

                int quantity_sold[]={0,0,0,0,0};

               

                int ch=0;

                int p_id,qty;

                //looping until user wishes to quit

                while(ch!=3){

                                showMenu();//displaying menu

                                cin>>ch;

                                if(ch==1){

                                                //showing sub menu, getting product id, and quantity,

                                                //updating the quantity array

                                                string sentinel="y";

                                                while(sentinel=="y"){

                                                                cout<<"Enter product id and quantity: ";

                                                                cin>>p_id;

                                                                cin>>qty;

                                                                //updating the quantity sold for the given product

                                                                switch(p_id){

                                                                                case 1:quantity_sold[0]+=qty;

                                                                                                break;

                                                                                case 2:quantity_sold[1]+=qty;

                                                                                                break;

                                                                                case 3:quantity_sold[2]+=qty;

                                                                                                break;

                                                                                case 4:quantity_sold[3]+=qty;

                                                                                                break;

                                                                                case 5:quantity_sold[4]+=qty;

                                                                                                break;

                                                                                default: cout<<"Invalid product ID"<<endl;        

                                                                }

                                                                //prompting to continue or not

                                                                cout<<"Do you want to add more? y/n: ";

                                                                cin>>sentinel;

                                                }

                                }else if(ch==2){

                                                //displaying all sales report

                                                double totalSales=0;

                                                for(int i=0;i<5;i++){

                                                                cout<<"Product "<<(i+1)<<", Quantity sold: "<<quantity_sold[i]<<", Retail value: $";

                                                                double retailValue=prices[i]*quantity_sold[i];

                                                                cout<<retailValue<<endl;

                                                                totalSales+=retailValue;

                                                }

                                                cout<<"Total Retail Value: $"<<totalSales<<endl;

                                }else if(ch==3){

                                                //end of loop

                                                cout<<"Thank you!"<<endl;

                                }else{

                                                cout<<"Invalid choice!"<<endl;

                                }

                               

                }

               

}

/*OUTPUT*/

1. Enter products sold

2. Display total retail value

3. Exit

Enter your choice: 1

Enter product id and quantity: 1 3

Do you want to add more? y/n: y

Enter product id and quantity: 2 3

Do you want to add more? y/n: y

Enter product id and quantity: 6 1

Invalid product ID

Do you want to add more? y/n: y

Enter product id and quantity: 5 3

Do you want to add more? y/n: y

Enter product id and quantity: 3 4

Do you want to add more? y/n: n

1. Enter products sold

2. Display total retail value

3. Exit

Enter your choice: 2

Product 1, Quantity sold: 3, Retail value: $8.94

Product 2, Quantity sold: 3, Retail value: $13.5

Product 3, Quantity sold: 4, Retail value: $15.92

Product 4, Quantity sold: 0, Retail value: $0

Product 5, Quantity sold: 3, Retail value: $20.61

Total Retail Value: $58.97

1. Enter products sold

2. Display total retail value

3. Exit

Enter your choice: 3

Thank you!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote