program help

From: dan (damanj23_at_aol.com)
Date: 10/30/03


Date: 29 Oct 2003 23:13:18 -0800

I need help in figuring out what to do for this program, it is a
program that reads book id, unit price, book purchased, book sold,
book returned, and city(respectively). It is a control break program
that prints a report for each city on a separate screen with a total,
then at the end it has a grand total. It prints to the screen and an
output file.
Input file looks like (the char is the city)
200 1.40 30 13 1 B
201 7.50 13 1 0 B
202 2.50 50 23 3 B
198 5.00 45 15 2 C
200 1.40 13 2 0 C
201 7.85 15 5 0 N
202 2.25 50 30 1 N
155 3.50 11 5 1 P

sample output

Store: Bloomington (which is all the ones with the letter B at the
end)
ID Price Purchase Sold Returns Inventory Value
200 1.40 30 13 1 25.20
201 7.50 13 1 0 90.72
202 2.50 50 23 3 76.35
Total: 93 37 4 192.27
then one for city C, N, and P
Then a grand total for all the citys put together

Here is what i got so far that is probably not close to working

#include <iostream>
#include <cctype>
#include <iomanip>
#include <fstream>
#include <cstdlib>

using namespace std;

void Header();
void ReadInput(istream& ins, int& id, double& unitPrice, int&
purchased, int& sold,
                           int& returned, char& city);

int main()
{
        ifstream infile;
        ofstream outfile;
        
        infile.open("a:\\comics.txt");
        if (infile.fail( )) {
                cout << "Input file opening failed.\n";
                system("pause");
                exit(1);
        }
        outfile.open("a:\\inventory.txt");
        if (outfile.fail( )) {
                cout << "Output file opening failed.\n";
                system("pause");
                exit(1);
        }
        // format double on the screen to print with 2 decimals
        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(2);
        // format doubles in the output file to print with 2 decimals
        outfile.setf(ios::fixed);
        outfile.setf(ios::showpoint);
        outfile.precision(2);

        int id, purchased, sold, returned;
        double unitPrice;
        int totalBooks = 0;
        double invVal = 0;
        char city;
        int totalPurchased = 0, totalSold = 0, totalReturned = 0;
        double totalInvVal = 0;
        Header();
        ReadInput(infile, id, unitPrice, purchased, sold, returned, city);
        totalBooks = (purchased - sold + returned);
        invVal = (unitPrice * totalBooks);
        bool first = true;
        int oldCity = 0;
        while(infile >> id >> unitPrice >> purchased >> sold >> returned >>
city);
        {
                infile >> city;
                //if (!first && oldCity != city)
        {
        switch(city)
        {
        case 'B':
                cout << "Store: Bloomington";
                break;
        case 'N':
                cout << "Store: Normal";
                break;
        case 'C':
                cout << "Store: Champaign";
                break;
        case 'U':
                cout << "Store: Urbana";
                break;
        case 'P':
                cout << "Store: Peoria";
                break;
        }
        cout << endl << endl;
                totalPurchased += purchased;
                totalSold += sold;
                totalReturned += returned;
                totalInvVal += invVal;
                outfile << "ID\t" << "Price\t" << "Purchase " << "Sold " <<
"Returns "
                        << "Inv. Value\n";
                cout << "ID\t" << "Price\t" << "Purchase " << "Sold " <<
"Returns "
                        << "Inv. Value\n";
                outfile << id << "\t" << unitPrice << "\t" << purchased << "\t "
<< sold << "\t "
                        << returned << "\t " << invVal;
                cout << id << "\t" << unitPrice << "\t" << purchased << "\t " <<
sold << "\t "
                        << returned << "\t " << invVal;
                cout << endl << endl;
                cout << "Totals\t\t" << totalPurchased << totalSold << totalReturned
                        << totalInvVal;
        }
                first = false;
                oldCity = city;
        }

        infile.close( );
        outfile.close( );
        cout << endl << endl;
        system("pause");
        return EXIT_SUCCESS;
}
void ReadInput(istream& ins, int& id, double& unitPrice, int&
purchased,
                           int& sold, int& returned, char& city)
{
        ins >> id >> unitPrice >> purchased >> sold >> returned >> city;

}
void Header()
{
        using namespace std;
        cout << "\t\tCosmic Comics Inventory Report by Store\n";
        cout << "\t\t Prepared by Daniel Buenger\n";
        cout << "\t\t\t Date: Oct/30/2003\n\n";
}

Thanks in advance,
B14



Relevant Pages

  • need help totaling one city at a time
    ... I am wondering if anyone can tell me how to add the totals city by ... void ReadInput(istream& ins, int& id, double& unitPrice, int& ... purchased, int& sold, ...
    (comp.lang.cpp)
  • Re: home sale question
    ... purchase price 38K; ... Also, as I understand it, since the sold home has been our principal ... residence then no capital gains taxes are ... for business purposes after 05/06/1997. ...
    (misc.taxes)
  • Re: What a Hobby
    ... and looked at my pins the other night,and felt pretty ... Seems you have been busy like me in the new hobby, bought my first pin about 12 months ago and have a collection of 6 at the moment and have also purchased and sold a few. ... Here is my list in order of purchase: ...
    (rec.games.pinball)
  • Re: home sale question
    ... purchase price 38K; ... Also, as I understand it, since the sold home has been our principal ... residence then no capital gains taxes are ... business purposes after 05/06/1997. ...
    (misc.taxes)
  • Re: three hundred dimentions?
    ... StoreID INT, ... > your product dimension, then you wouldn't have to worry. ... Need to know, for each item sold, what ... >> the ratios that any other items are sold in the same transaction. ...
    (microsoft.public.sqlserver.olap)