Write a program that acts as a self-checkout register at a store and lets the us
ID: 660581 • Letter: W
Question
Write a program that acts as a self-checkout register at a store and lets the user buy 2 items
The program will prompt the user and read in:
- the name of item 1. The name can be multiple words with space in between.
- the price of item 1 and number of items 1. Read both the price and the number in one C++ statement
- the name of item 2. The name can be multiple words with space in between.
- the price of item 2 and the number of items 2. Read both the price and the number in one C++ statement
Then the program calculates the total cost of the items, including the sales tax of 8.675%.
The tax should be defined as a constant in the program, and not used as a literal.
Last, the program prints the receipt on screen in the following format:
Item Count Price Ext. Price
==== ===== ===== ========
Item 1 Name Num Price Price * Num
Item 2 Name Num Price Price * Num
Tax Tax * SubTotal
Total Total
The output should be in column format, and the prices are with 2 digits after the decimal point.
You can assume the item names will not be more than 20 characters wide.
Explanation / Answer
please find the required solution:
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
const double salestax = 8.675;
int main()
{
string name1 = "",name2 = "";
int numItem1,numItem2;
double price1,price2,tax,total;
cout << "enter the name of item 1:";
getline(cin, name1);
cout<<"enter the price of item 1 and number of items 1";
cin>>price1>>numItem1;
cout << "enter the name of item 2:";
getline(cin, name2);
cout<<"enter the price of item 2 and number of items 2";
cin>>price2>>numItem2;
cout<<"Item Name Count Price Ext.price"<<endl;
cout<<"========= ===== ===== ========= "<<endl;
cout<<name1;
printf(" %d %.2f %.2f",numItem1,price1,(numItem1*price1));
cout<<name2;
printf(" %d %.2f %.2f",numItem2,price2,(numItem2*price2));
total=(numItem1*price1)+(numItem2*price2);
tax=total*8.675/100;
cout<<"tax:"<<tax;
cout<<"total"<<(total+tax);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.