|
-
Feb 7th, 2002, 10:58 AM
#1
Thread Starter
Addicted Member
Program Help
This code is for a grocery store and has two problems that I can not fix - the check for double input valeus from the file doesn't work, and it won't recognize a single value entered, even if it's in the list.
Code:
/**********************************************************************************************
* Store Checkout Program - 1/22/02 - Justin C. Roberts *
**********************************************************************************************/
// Insert header files and namespace
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
// Setup variables and arrays
ifstream inFile;
ofstream outFile;
string arrProDesc[50];
const double TAX = 0.075;
int cont = 0, count = 0, count2 = 0, prodNum = 0, prodQuan = 0, customer = 0, total = 0, arrProNum[50], arrProNB[50];
float arrProPrice[50], subtotal = 0, tax = 0;
char arrProTax[50], con;
void main()
{
// Variables declared for file I/O and storing the input
outFile.open("Receipts.out");
inFile.open("invent.in");
// Loop in the contents of the file and check for double input values
while (inFile)
{
inFile >> arrProNum[total] >> arrProDesc[total] >> arrProPrice[total] >> arrProTax[total];
for (count = 0; count < total; count++)
{
if (total > 0)
{
if (arrProNum[total] == arrProNum[count - 1])
{
outFile << "*** Duplicate product number: " << arrProNum[total] << endl;
total--;
}
}
}
total++;
}
count = 0;
// Output reciept header
outFile << "Welcome to Jrob's Store!" << endl;
while (cont == 0)
{
outFile << "Customer " << customer << ":" << endl;
// Welcome user and obtain input, do error checking
cout << "Welcome, please enter the <product number> <quantity> from the inventory list to place your order. When you are finished, enter a '0' for the product number." << endl;
for (count = 0; count < total; count++)
{
cin >> prodNum;
if (prodNum == 0)
goto newCustomer;
cin >> prodQuan;
if (prodQuan <= 50 && prodNum != 0)
{
for (count2 = 0; count2 < total; count2++)
{
if (prodNum == arrProNum[count2])
{
arrProNB[count2] = prodQuan;
outFile << setw(7) << arrProDesc[count2] << setw(8) << arrProNB[count2] << setw(7) << arrProPrice[count2] << setw(5) << arrProTax[count2] << endl;
subtotal = subtotal + (arrProPrice[count2] * arrProNB[count2]);
if (arrProTax[count2] == 'T')
tax = tax + ((arrProPrice[count2] * arrProNB[count2]) * TAX);
count2 = total;
break;
}
else if (count2 = total)
{
outFile << "*** Product #" << prodNum << " could not be found." << endl;
break;
}
}
}
else
outFile << "*** Cancelled order of Product # " << prodNum << ", not enough to fulfill order." << endl;
}
newCustomer: outFile << "-----------------------------------------" << endl;
outFile << "Subtotal: " << subtotal << endl;
outFile << "Tax: " << tax << endl;
outFile << "-----------------------------------------" << endl;
outFile << "Total: " << (subtotal + tax) << endl << endl;
cout << "Another customer? (y/n)" << endl;
cin >> con;
if (con == 'y')
customer++;
else
cont = 1;
}
}
Here is the input file:
10000 Bread 2.26 N
20000 Butter 2.35 T
30000 Soup 3.59 N
40000 Carrots 2.79 N
50000 Potatos 5.89 T
50000 Stuff 5.67 N
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|