Question

In: Computer Science

In this assignment, you need to demonstrate your ability in using input, output, data types, and...

In this assignment, you need to demonstrate your ability in using input, output, data types, and if statement in C++ program. Assume that you need write a C++ program for a cash register. There are only four items in the store: Cereal, $3.99 Milk, $3.99 Egg, $0.25 Water, $ 1.50 Once a customer purchases items, you will ask her/his how many of them are bought. The quantity can be in the range of 0-10 (including 0 and 10). Then, calculate total for this transaction. Later ask for payment method, which could be either Credit Card or Cash. Do not use string variables. Just use char variables, for instance “1” for Credit Card, “2” for Cash. If the payment method is CC, your program exits. If it is cash, and enter the amount received from customer. Then show the due amount the customer. An example scenario for a CC payment: Enter how many cereal boxes customer bought:2 Enter how many milk jars customer bought:1 Enter how many eggs customer bought:3 Enter how many water bottles customer bought:0 Total is $12.72 Payment Method: 1 Thanks... An example scenario for a cash payment: Enter how many cereal boxes customer bought:1 Enter how many milk jars customer bought:0 Enter how many eggs customer bought:6 Enter how many water bottles customer bought:5 Total is $12.99 Payment Method: 2 Enter the amount received from customer: 20.00 Due amount is $7.01 Thanks...

Solutions

Expert Solution

Program:

#include<iostream>
using namespace std;

int main()
{
   //constants that hold price of items
    const double PRICE_OF_CEREAL = 3.99;
    const double PRICE_OF_MILK = 3.99;
    const double PRICE_OF_EGG = 0.25;
    const double PRICE_OF_WATER = 1.50;
   
    //variable declarations;
    int cerealsBought, milkBought, eggsBought, waterBought;
    double totalPrice, cashReceived, balanceAmt;
    char paymentMethod;
   
    //prompt and read the number of cereal noxes bought
    cout << "Enter how many cereal boxes customer bought: ";
    cin >> cerealsBought;
    //prompt and read number of milk jars bought
    cout << "Enter how many milk jars customer bought: ";
    cin >> milkBought;
    //prompt and read number of eggs bought
    cout << "Enter how many eggs customer bought: ";
    cin >> eggsBought;
    //prompt and read number of water bottels bought
    cout << "Enter how many water bottles customer bought: ";
    cin >> waterBought;
   
    //conpute the total price of products bought
    totalPrice = (cerealsBought * PRICE_OF_CEREAL) + (milkBought * PRICE_OF_MILK) + (eggsBought * PRICE_OF_EGG) + (waterBought * PRICE_OF_WATER);
    //display the total amount
    cout << "Total is $" << totalPrice << endl;
   
    //prompt and read payment method
    cout << "Payment method (1 for Credit Card, 2 for Cash): ";
    cin >> paymentMethod;
   
    //if payment method is 1 terminate the program
    if(paymentMethod == '1')
        cout << "Thanks..." << endl;
    else
    {
        //read the cash received from customer
       cout << "Enter the amount received from customer: ";
       cin >> cashReceived;
       //check if amount entered is greater than total else reprompt
       while(cashReceived < totalPrice)
       {
          //display error message
          cout << "Cash entered is less than total price. Retry.." << endl;
          //read the cash received from customer
           cout << "Enter the amount received from customer: ";
           cin >> cashReceived;
       }
       //compute the due amount;
       balanceAmt = cashReceived - totalPrice;
       //display the due amount
       cout << "Due amount is $" << balanceAmt << endl;
       cout << "Thanks...";  
   }
    return 0;
}

Output:

Program Screenshot:


Related Solutions

Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to...
Struct PERSON Assignment Outcomes: Demonstrate the ability to create structs using typedef Demonstrate the ability to create an array of structs Program Specifications: DESIGN and IMPLEMENT a program that will CREATE and use three different variables of type PERSON. Create a struct using the typedef command for a DATE. Create a struct for a PERSON with the following fields. name [this will be a string] birthdate [this will be a DATE] gender [this will be a char] annualIncome [this will...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output)...
In this assignment, you are going to write a Python program to demonstrate the IPO (Input-Process-Output) cycle that is the heart of many imperative programs used for processing large amount of data. Daisy is recently hired by a warehouse. One of her job is to keep track the items ordered by all the branches of the company. The company wants to automate the task using a computer program. Being a friend of Daisy, she knows you are a Computer Science...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability...
Purpose The purpose of this assignment is to give you an opportunity to demonstrate your ability to identify emerging ethical issues in business, interpret the multitude of perspectives inherent in your case study, and model appropriate behaviour by recommending specific solutions. How to Proceed Select a case. It can be one of the textbook cases that we have not discussed during the course. It can also come from the outside world, perhaps a case you have been following in the...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to...
"Gambling Greg" Assignment Outcomes: Demonstrate the ability to create and use structs Demonstrate the ability to create and use menus Demonstrate the ability to create and use an array of structs Demonstrate the ability to generate and use random numbers Program Specifications: Assume that gambling Greg often goes to the Dog Racing Track. Greg loves to bet on the puppies. In each race Greg will place a wager and pick a dog. The dog information will be stored in a...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate...
Playing with strings Assignment Outcomes: Demonstrate the ability to create strings. Demonstrate the ability to manipulate strings. Demonstrate the ability to write well written code. Program Specifications: DESIGN and IMPLEMENT a short program that will: Allow the user to enter a string with up to 100 letters. Display the user-entered string: Forward Backward Vertical As a triangle made from the letters of the string Display the number of letters in the string. Once everything above is displayed, the program will...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret...
Policy Drivers The purpose of this assignment is to practice and demonstrate your ability to interpret detailed policy. We have chosen for you to take a look at two of the most well known policies; in real life, you will have government polices such as these as well as enterprise specific policies or regulations. As you build information systems, it is key to early on in the process to identify all relevant policy drivers and understand them. In the module,...
In this assessment, you will need demonstrate your ability to distinguish Value creation and Waste (Lean...
In this assessment, you will need demonstrate your ability to distinguish Value creation and Waste (Lean SixSigma). 1. Select and briefly describe a service process you have recently witnessed in your everyday life (buying bread, renting a car, booking a flight ticket, contacting customer service, etc.). Then, describe the process further as follows: 2. Break the process down into at least 5 logical and chronological activities. – 2 points 3. Identify at least 2 activities in the process that create...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and...
Assignment Overview IN C++ This assignment will give you practice with numerical calculations, simple input/output, and if-else statements. Candy Calculator [50 points] The Harris-Benedict equation estimates the number of calories your body needs to maintain your weight if you do no exercise. This is called your basal metabolic rate or BMR. The calories needed for a woman to maintain her weight is: BMR = 655 + (4.3 * weight in pounds) + (4.7 * height in inches) - (4.7 *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT