I need to know where I am going wrong in this code.
These were my instructions:
Do not use arrays or tables, functions are not required. I am providing you a file called Stock.txt that contains information regarding the 9 different stock items carried by THRIFTY SALES, INC. The file is a repeating sequence of three records such that the first record represents an item code number, the second record represents the description of each item and the third record contains the current selling price. Then the sequence repeats. Your program is to simulate the checkout register allowing the check out clerk to input item codes to obtain the current selling prices and descriptions. If an incorrect code is entered, the clerk should be notified by an appropriate message on the screen. If the item is found, the clerk will enter the number of items with that description and price and continue to the next item. When all items have been entered the clerk terminates the transaction by entering an item code of 0 (zero). The program will build a sales slip called Sales.txt enumerating the item code, description, unit price, quantity purchased, and total extended price. The bill will be subtotaled and an 8% sales tax added for a final total. Amount tendered by the customer and change given will be finally added to the invoice. This invoice should be written out to an output file called Sales.txt. The final total and change should appear on the screen as well.
Your output file should line up all columns and output formatted for dollars and cents on money amounts, using setprecision, showpoint, and fixed. Make sure you format your output to the screen as well.
This assignment uses file processing found in chapter 5.
Do not use arrays or tables.
This is what I have so far:
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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
int ans;
int itemNum;
int amt;
char response;
float subtotal;
float total;
int taxRate = 0.08;
float tax;
float moreMoney;
float money;
float change;
bool found;
ofstream outputFile;
int itemNumber;
string description;
double price;
outputFile.open ("sales.txt");
if (!outputFile)
{
cout << "The File (sales.txt) failed to open";
}
total = 0;
cout << "What Item number would you like me to look up for you?"<<endl;
cin>> itemNum;
while (itemNum != 0);
{
ifstream inputFile;
inputFile.open ("stock.txt");
inputFile >> itemNumber;
inputFile >> description;
inputFile >> price;
if (!outputFile)
{
cout << "The File (sales.txt) failed to open";
}
int count;
for ( count = 1; count <= 9; count++);
{
if ( itemNum = itemNumber);
{
cout << "Item number " << itemNumber << ", is pulling up " << description << " and costs $" << price << " per item." << endl;
cout << "How many " << description << " would you like to purchase?" << endl;
cin >> amt;
subtotal = price * amt;
total += subtotal;
outputFile << itemNumber;
outputFile << description;
outputFile << amt;
outputFile << subtotal;
}
}
cout << "OK, I've Added " << amt << " " << description << " to your order." << endl;
}
if (itemNum = 0);
{
cout << fixed << showpoint << setprecision (2);
tax = subtotal * .08;
cout << "Tax : $" << tax <<endl;
total = subtotal + tax;
cout << "Your Total is : $" << total << endl;
cout << "How much would you like to pay?"<< endl;
cin >> money;
while (money < total);
{
cout << "I'm sorry, but that is not enough money to cover the Total. How much more would you like to give?"<< endl;
cin >> moreMoney;
moreMoney = money + moreMoney;
}
}
cout << fixed << showpoint << setprecision (2);
change = money - total;
cout << "Your change is : $" << change << endl;
outputFile << tax;
outputFile << total;
outputFile << money;
outputFile << change;
outputFile.close ();
return 0;
}
|