asked 66.4k views
0 votes
Write a C++ programthat simulates a cash register. The user should keeptyping

in the prices of items andthe register must keep adding them up. When the user

types a 0, the registershould add up the prices of all the items, add 8% salestax,

and output the finaltotal. Example output is given below.


Enter the price of item 1: 5.00

1 Answer

3 votes

Answer:

//C++ code for the cash register..

#include <iostream>

#include<vector> //including vector library

using namespace std;

int main() {

vector<float> cash; //declaring a vector of type float.

float item=2,cash_sum=0;

int counter=1;

while(item!=0)//inserting prices in the vector until user enters 0...

{

cout<<"Enter the price of item "<<counter<<" :"<<endl;

cin>>item;

counter++;

cash.push_back(item);//inserting element in the vector...

}

for(int i=0;i<cash.size();i++)//looping over the vector...

{

cash_sum+=cash[i];//summing each element..

}

cash_sum*=1.08;//adding 8% sales tax.

cout<<cash_sum;//printing the result....

return 0;

}

Step-by-step explanation:

I have taken a vector of type float.

Inserting the price of each item in the vector until user enters 0.

Iterating over the vector for performing the sum operation.

Then after that adding 8% sales tax to the sum.

Printing the output at last.

answered
User Shanthakumar
by
8.0k points