1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string exitCheck;
string
productname1,
productname2,
productname3;
double
quantity1,
quantity2,
quantity3;
double
price1,
price2,
price3;
int qtyItemsTotal{}, count{};
//double quantity = 0, price = 0, qprice{}, flist{}; // <--- These variables should no longer be needed.
double lineTotal{}, priceTotal{}; // <--- Maybe this would be a better name.
cout << fixed << setprecision(2); // <--- May or may not be needed.
do
{
if (count == 0)
{
cout << "Product name: ";
getline(cin, productname1);
exitCheck = productname1;
}
if (count == 1)
{
cout << "Product name: ";
getline(cin, productname2);
exitCheck = productname2;
}
if (count == 2)
{
cout << "Product name: ";
getline(cin, productname3);
exitCheck = productname3;
}
// <--- Add as many as you want.
if (exitCheck == "x" || exitCheck == "X")
{
cout << "\n - OFFICIAL RECEIPT -\n";
cout << "Qty Product name Price\n";
for (int idx = 0; idx < count; idx++)
{
if (idx == 0)
{
cout << quantity1 << " " << productname1 << price1 * quantity1 << '\n';
}
if (idx == 1)
{
cout << quantity2 << " " << productname2 << price2 * quantity2 << '\n';
}
if (idx == 2)
{
cout << quantity3 << " " << productname3 << price3 * quantity3 << '\n';
}
}
cout << "Total\n";
cout << sum1 << " item(s) " << sum;
break;
}
cin.ignore(1000, '\n');
lineTotal = quantity * price;
qtyItemsTotal += quantity;
priceTotal += lineTotal;
} while (1);
return 0;
}
|