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 (cin won’t work)
- the price of item 2 and the number of items 2. Read both the price and the number in one C++ statement
The program calculates the total cost of the items, including the sales tax of 9.25%.
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.
Example program output:
(In this example the user buys mechanical pencils and binders, note that the item name is repeated in the second prompt of each item)
Enter the name of item 1: mechanical pencil
Enter the number of mechanical pencil(s) and the price of each: 2 2.50
Enter the name of item 2: binder
Enter the number of binder(s) and the price of each: 3 7.25
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float price1, price2; // The price of 2 items
int quantity1, quantity2; // The quantity of 2 items
cout << setprecision(2) << fixed << showpoint;
cout << "Please input the price and quantity of the first item" << endl;
cin >> price1 >> quantity1;
cout << endl << "Please input the price and quantity of the second item\n";
cin >> price2 >> quantity2;
cout << left << setw(16) << "PRICE" << right << setw(12) << "QUANTITY" << endl << endl;
Not at all, the code is just to give you an idea. My recommendation would be to break down the program into small parts. Read about getline from the string library. You will probably have to use the cin.ignore() so I would read up on it.
The same recommendation that you got in your other post still applies (i.e. setw and setprecision())
It looks like you are on a right track. Keep working on your code and keep posting the updates as you go.