Question

In: Computer Science

Write a program that simulates a cashier terminal. Assume that a customer is purchasing an unknown...

Write a program that simulates a cashier terminal. Assume that a customer is purchasing an unknown number of different merchandise items, possibly with multiple quantities of each item. Use a while loop to prompt for the unit price and quantity. The loop should continue until the unit price is zero. Display a subtotal for each item. After the loop display the total amount due. Use currency format where appropriate. See Sample Run (inputs shown in blue).

You must use a while loop. Thanks so much.

What lies below is a sample run, the output should look like this:


Sample Run
Enter item price or zero to quit
2.49
Enter quantity for this item
3
Total this item is $7.47

Enter item price or zero to quit

3.79

Enter quantity for this item

2

Total this item is $7.58


Enter item price or zero to quit

5.99

Enter quantity for this item

4

Total this item is $23.96


Enter item price or zero to quit

0

Total is $39.01

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

#include <iostream>
using namespace std;

int main()
{
double total=0;
   while(1)
   {
   int quantity;
   double price;
   cout<<"\nEnter item price or zero to quit"<<endl;
   cin>>price;
  
   // If price is zero, then break
   if(price==0)
   break;
  
   cout<<"Enter quantity for this item"<<endl;
   cin>>quantity;
  
   double temp=quantity*price;
   //add to the total
   total += temp;
  
   cout<<"Total this item is $"<<temp<<endl;
   }
  
   cout<<"\nTotal is $"<<total;
   return 0;
}

==================================

SCREENSHOT:


Related Solutions

In C++  Write a program that simulates coin tossing. For each toss of the coin the program...
In C++  Write a program that simulates coin tossing. For each toss of the coin the program should print heads or tails. Let the program toss the coin 100 times and count the number times each side of the coin appears. Print the results. 0 represents tails and 1 for heads.
Write a java program that simulates thousands of games and then calculate the probabilities from the...
Write a java program that simulates thousands of games and then calculate the probabilities from the simulation results. Specifically in the game, throw two dice, the possible summations of the results are: 2, 3, ..., 12. You need to use arrays to count the occurrence and store the probabilities of all possible summations. Try to simulate rolling two dice 100, 1000, 10,0000 times, or more if needed. Choose one simulation number so that the probabilities you calculated is within 1%...
3. Write a program that simulates a vending machine.   The user will be prompted to enter...
3. Write a program that simulates a vending machine.   The user will be prompted to enter a number then a letter. As part of the prompt you must display a message to indicate the number and letter, along with the possible choices. That is, what selections will give user which item.   If the user enters a number or a letter that is not valid, then display the message “Bad Entry” and end the program. (100 pts) Selections with messages. 1a...
Write a python program that simulates a simple dice gambling game. The game is played as...
Write a python program that simulates a simple dice gambling game. The game is played as follows: Roll a six sided die. If you roll a 1, 2 or a 3, the game is over. If you roll a 4, 5, or 6, you win that many dollars ($4, $5, or $6), and then roll again. With each additional roll, you have the chance to win more money, or you might roll a game-ending 1, 2, or 3, at which...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following...
Using a (GUI interface), write a Java program that simulates an ATM machine with the following options menu: "Welcome" 1. Deposit to account 2. Withdraw 3. Exit
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this...
You will write a program using Python that simulates an Automatic Teller Machine (ATM). For this program, your code can have user defined functions (but not required), the program must not call on any external functions or modules to handle any of the input, computational, and output requirements. Requirements: There is a customer with the following credential and can only access the system if the Access Code is correct: • Name: Peter Parker, Access Code: 2222 • When the program...
Objective: Write a program that simulates a robot running a queue of commands to move around...
Objective: Write a program that simulates a robot running a queue of commands to move around a board with obstacles. Requirements: The board is composed of spaces that are either empty (“_”) or have an obstacle (“X”). Also the board is assumed to be 10x10 spaces. The robot (“O”) has an x and y position corresponding to its location on the board, and four commands: move up, move down, move left, and move right. Both the board and the robot’s...
Objective: Write a program which simulates a hot potato game. In this version of a classic...
Objective: Write a program which simulates a hot potato game. In this version of a classic game, two or more players compete to see who can hold onto a potato the longest without getting caught. First the potato is assigned a random value greater than one second and less than three minutes both inclusive. This time is the total amount of time the potato may be held in each round. Next players are put into a circular list. Then each...
Write a program in Objective C that takes an integer keyed in from the terminal and...
Write a program in Objective C that takes an integer keyed in from the terminal and extracts and displays each digit of the integer in Eglish. So if the user types 647, the program should display the following: six four seven
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays...
Write a program that simulates a Magic 8 Ball, which is a fortune-telling toy that displays a random response to a yes or no question. In the student sample programs for this book, you will find a text file named 8_ball_responses.txt. The file contains 12 responses, such as “I don’t think so”, “Yes, of course!”, “I’m not sure”, and so forth. The program should read the responses from the file into a list. It should prompt the user to ask...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT