Answer to Question #179779 in C++ for bryan mike

Question #179779

create a program using switch statement that can be used to compute for a POS of small school supplies


1
Expert's answer
2021-04-09T13:35:42-0400
#include <iostream>
#include <string>
#include <iomanip>


using namespace std;

int main(void)
{
        //Declare all the required variables..
        double const rate_of_tax=0.06;
        double  total= 0.0,count=0.0,final_Amt=0.0,taxTotal=0.0;
        //Declare all the items in the array..
        string     items[]         = {"Pencil", "Sharpner", "Eraser", "Pen", "Ruler", "Cookies", "Notebook", "Newspaper"};
        int item_no;
        int quantity;

        // Display the menu of item with prices..
    cout<<"Item_No "<<" Item Name \t\t"<<"Cost\n";
        cout << "0.        " << items[0] <<"\t\t\t$" <<  "0.85" << endl;
        cout << "1.        " << items[1] <<"\t\t$" << "1.56" << endl;
        cout << "2.        " << items[2] <<"\t\t\t$" <<  "0.65" << endl;
        cout << "3.        " << items[3] <<"\t\t\t$" <<  "1.85" << endl;
        cout << "4.        " << items[4] <<"\t\t\t$" <<  "2.84" << endl;
        cout << "5.        " << items[5] <<"\t\t$" << "5.76" << endl;
        cout << "6.        " << items[6] <<"\t\t$" << "7.45" << endl;
        cout << "7.        " << items[7] <<"\t\t$" << "0.97" << endl;
    //To take input from user..
        cout << "Enter the item number : " << endl;
        cin >> item_no;
        cout << "Enter the quantity of item : " << endl;
        cin >> quantity;
        //Run a  while loop until user enters quantity as less than or equal to 0..
        while(quantity > 0)
        { 
            //Add the quantity into count..
            count+=quantity;
            //switch statement to run each case..
            switch(item_no)
            {
                case 0:
                       total=quantity*0.85;
                       break;
                case 1:
                       total=quantity*1.56;
                       break;
                case 2:
                       total=quantity*0.65;
                       break;
                case 3:
                       total=quantity*1.85;
                       break;
                case 4:
                       total=quantity*2.84;
                       break;
                case 5:
                       total=quantity*5.76;
                       break;
                case 6:
                       total=quantity*7.45;
                       break;
                case 7:
                       total=quantity*0.97;
                       break;
            }
            //add total into final_Amt..
            final_Amt+=total;
            //To take input from user..
                cout << "Enter the item number : " << endl;
                cin >> item_no;
                cout << "Enter the quantity of item : " << endl;
                cin >> quantity;
        }
        //To apply Discount ..
        if(count>=8)
        {
            cout<<"Discount of 5 percent applied!\n";
            final_Amt=final_Amt*0.95;
        }
        //Calculate the tax..
    taxTotal+=final_Amt*rate_of_tax;
    //Add final_Amt and taxTotal..
    final_Amt=final_Amt+taxTotal;
    //Print the output..
        cout << "Total quantity of items are : " << count << endl;
        cout << "Total Tax is : " << taxTotal << endl;
        cout << "Total amount of the items are : " << final_Amt<< endl;
        
        
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS