In: Computer Science
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
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:


