Answer to Question #180224 in C++ for Rose

Question #180224

Problem 2

•Develop a program working as a soda vending machine. The program should show the product menu with price and take user input for product number, quantity and pay amount. The output should show the total sale price including tax and the change.

Input

1.Product Number

2.Product Quantity

3.Payment Amount

Process

1.Show menu

2.Calculate purchase

3.Take payment

4.Calculate tax

5.Calculate Total purchase

6.Calculate Change

Output

1.Total Purcahse

2.Tax (6% of Total Purcahse )

3.Change

**************Vending Machine ****************

1.     Coke $1.25

2.     Pepsi $1.00

3.     Water $2.00

4.     Coffee $1.50

5.     Exit Menu

Enter your Choice:1

How many do you want?1

How much is your payment?2

Tax Amount : $0.075

Total Purchase :$1.325

Change : $0.675


1
Expert's answer
2021-04-11T05:17:56-0400
#include <iostream>
#include <string>
using namespace std;
struct Product
{
    short id;
    string name;
    double price;
};
void printInfo(Product product) {
    if (product.name == "Exit Menu")
    {
        cout << product.id << ".  " << product.name << endl;
    }
    else
    {
        cout << product.id << ".  " << product.name << "   $" << product.price << endl;
    }
}
int main()
{
    Product drink[5];
    drink[0] = { 1, "Coce",1.25 };
    drink[1] = { 2, "Pepsi",1.00 };
    drink[2] = { 3, "Water",2.00};
    drink[3] = { 4, "Coffee",1.50};
    drink[4] = { 5, "Exit Menu",0 };
   
    cout << "**************Vending Machine ****************" << endl;
    for (int i = 0; i < 5; i++)
        {
            printInfo(drink[i]);
        }
    int choise{ 0 };
    double payment;
    int quantity;
    double total_payment;
    double tax_ammount;
    double change;
    while (true) 
    {
        cout << "Enter your Choice: ";
        cin >> choise;
        if (choise == 5) 
        {
            break;
        }
        cout << "How many do you want? ";
        cin >> quantity;
        cout << "How much is your payment? ";
        cin >> payment;
        total_payment = drink[choise-1].price * quantity;
        tax_ammount = (total_payment / 100) * 6;
        cout<<"Tax Amount : $" << tax_ammount << endl;
        total_payment += tax_ammount;
        change = payment - total_payment;
        cout << "Total Purchase : $" << total_payment << endl;
        cout << "Change : $" << change << endl;
      }
    return 0;
}

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