Question
Ok, so here is the instructions that I have: Do not use arrays or tables, functions are not required. I am providing you a file
Ok, so here is the instructions that I have:
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 Dollar 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, usingsetprecision, 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.
--------------------------------------------------------------------------------------------------------------------------------
I have the majority of it written, but I can not figure out how to get it to read from the Stock.txt file correctly. I believe I need to use a FOR LOOP, but I can't figure out how to read the three lines together by the 9 items on the list.
This is what I have so Far:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PSEUDOCODE:
PROGRAM: Issue a receipt file (sales.txt) based off customer responses from stock.txt file
INPUTS: stock.txt file, customer responses
OUTPUTS: item number, item description, item price, line price, subtotal, tax, final total, change
FORMULAS: extended price of item = quantity purchased * unit price, subtotal = line price + each line price,
tax = subtotal * tax rate, final total = subtotal + tax, change = amount tendered - final total
start
open output file
item found = no
total = 0
get item number from user
REPEAT while item number is not 0
open stock.txt file
found = no
REPEAT 9 times
read 3 values (item number, description, price)
IF user's item number = number
display item number, description, price to the screen
ask user how many he would like to purchase
calculate the subtotal
add subtotal to total
write item number, description, quantity and subtotal to output file
found = yes
END-IF
END-REPEAT
IF found is still no
write error message to screen
END-IF
found = no
close input file
get next item number from customer
END-REPEAT
calcuate tax and display
add tax to total
display total
ask for money tendered
REPEAT while money tendered < total
display message asking for more money
get more money from customer
add money to money tendered
END-REPEAT
calculate change and display
write tax, total, money tendered, and change to output file
close output file
stop
--------------------------------------------------------------------------------------------------------------------
CODE I HAVE THUS FAR:
#include
#include
#include
using namespace std;
int main ()
{
string item;
int count;
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;
ifstream inputFile;
int itemNumber; string description; float price;
ofstream outputFile;
outputFile.open ("sales.txt");
found = false;
total = 0;
cout << "What Item number would you like me to look up for you?"< cin>> itemNum; count = 0; for ( itemNum != 0; count <= 9; count++); { inputFile.open ("stock.txt"); if (itemNum = itemNumber ) { inputFile >> itemNumber; inputFile >> description; inputFile >> price; if ( found = true); { 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 = total + subtotal; outputFile << itemNumber; outputFile << description; outputFile << amt; outputFile << subtotal; found = true; cout << "OK, I've Added " << amt << " " << description << " to your order." << endl; } } } while (itemNum = 0); { tax = subtotal * .08; cout << "Tax : $" << tax < 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; } } change = money - total; cout << "Your change is : $" << change << endl; outputFile << tax; outputFile << total; outputFile << money; outputFile << change; outputFile.close (); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started