Take any previous home assignment and modify it to save the
Solution
// C++ code determine tax and the total cost for the item and save it to output file
#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
#include <iomanip>
using namespace std;
int main ()
{
string filename;
cout << \"What is the filename to store to? \";
cin >> filename;
ofstream fin;
fin.open(filename.c_str());
if(!fin.is_open())
{
cout << \"could not open \" << filename << endl;
return 0;
}
string ItemName;
double unitPrice;
double numberItemSold;
double Subtotal;
double tax;
double shipping = 4.98;
double total;
cout << \"Enter Item name: \";
cin >> ItemName;
cout << \"Enter unit price: \";
cin >> unitPrice;
cout << \"Enter numbers of items sold: \";
cin >> numberItemSold;
Subtotal = unitPrice*numberItemSold;
tax = Subtotal*8.25/100;
total = Subtotal + tax + shipping;
fin <<left<< setw(30) << \"Unit price: \" << unitPrice << endl;
fin <<left<< setw(30) << \"Number of items sold: \" << numberItemSold << endl;
fin <<left<< setw(30) << \"Subtotal: \" << Subtotal << endl;
fin <<left<< setw(30) << \"tax: \" << tax << endl;
fin <<left<< setw(30) << \"Shipping: \" << shipping << endl;
fin << left<< setw(30) << \"Total: \" << total << endl;
return 0;
}
/*
output:
What is the filename to store to? output.txt
Enter Item name: cookie
Enter unit price: 23
Enter numbers of items sold: 12
output.txt
Unit price: 23
Number of items sold: 12
Subtotal: 276
tax: 22.77
Shipping: 4.98
Total: 303.75
*/

