Hi so I am suppose to write/fix this code up so it produces a monthly bill for a store. This is what I have so far. I know its suppose to have functions but im just doing it first this way because i find it easier.I think theres something wrong in the calculations because the output I am suppose to get is different than the output our prof provided. Also we are not allowed to use strings. the output i get is this

HIGH FASHION DEPARTMENT STORE
MONTHLY BILLING STATEMENT
132

DEPT NBR ITEM NBR AMOUNT OF PURCHASE DISCOUNT AMOUNT NET AMOUNT

2 12 8 0 8
12 8 0 8
TOTAL DEPT 3 8 0 16*

2 12 8 0 8
TOTAL DEPT 4 8 0 16*

2 12 8 0 8
NET TOTAL AMOUNT 16**
SALES TAX AT 7% 1
SERVICE CHARGE 0

FINAL TOTAL - (PLEASE PAY THIS AMOUNT) 17***

but the output should be(I attached a link for it)
http://prntscr.com/6n5qoy

and the input in the data file is
http://prntscr.com/6n5r3l

This is the purpose:
The High Fashion Department Store wants a program written to produce its monthly bills. Input to
the program will be the customer number, the number of the department in which that item was
purchased, the item number, and the amount of the purchase. There are four departments numbered
1 through 4. On all purchases of $10.00 or more in departments 1 and 2, the customer receives a 5
percent discount. On all purchases of $25.00 or more in departments 3 and 4, the customer receives
an 8 percent discount. Totals are to be produced for each department and for each customer. Sales
tax of 7 percent is paid on the net total for the customer. Also a service charge is added to the bill if
the amount of the bill is less than $100.00. The service charge is 10 percent of the net bill before the
sales tax is added if the total is less than $50.00. Otherwise, the service charge is 5 percent. The bill
for each customer is to be printed on a separate page. (You need a counter to keep track of the
number of print lines used.)
You have to use at least two functions for this assignment.

and this is what i have so far:

    #include<fstream>
    #include<iostream>
    #include<iomanip>
    #include<conio.h>
    using namespace std;
    #define in_file "data.txt"
    #define out_file "result.txt"
    void main ()
    {
    ifstream ins;
    ofstream outs;
    //open file
    ins.open(in_file);
    outs.open(out_file);
    //declare variables and constants
    const double discount1 = 0.05;
    const double discount2 = 0.08;
    const double sales_tax = 0.07;
    const double service_charge1 = 0.10;
    const double service_charge2 = 0.05;
    int customer (0);
    int department (0);
    int item (0);
    int purchase (0);
    int discount (0);
    int net (0);
    int net_total (0);
    int total (0);
    int service_charge (0);
    int total_purchase (0), total_discount (0), subtotal (0), SalesTax (0);
    int counter = 0;
    if (!in_file)
    cout << "Please input a proper input file." << endl;
    else
    {
    ins >> customer;
    if ( counter < 4 )
    {
    ins >> department >> item >> purchase >> customer;
    counter++;
    //calculations
    if ( department == 3 || department == 4)
    {
    if ( purchase >= 25 )
    {
    discount = purchase * 0.08;
    net = purchase - discount;
    }
    }
    else
    {
    net = purchase;
    }
    if ( department == 1 || department == 2)
    {
    if ( purchase >= 10 )
    {
    discount = purchase * 0.05;
    net = purchase - discount;
    }
    else
    {
    net = purchase;
    }
    }
    if ( department == 1 )
    {
    total_purchase += purchase;
    total_discount += discount;
    net_total += net;
    }
    if ( department == 2 )
    {
    total_purchase += purchase;
    total_discount += discount;
    net_total += net;
    }
    if ( department== 3 )
    {
    total_purchase += purchase;
    total_discount += discount;
    net_total += net;
    }
    if ( department == 4 )
    {
    total_purchase += purchase;
    total_discount += discount;
    net_total += net;
    }
    net_total += net_total;
    SalesTax = (net_total * sales_tax);
    subtotal = net_total + SalesTax;
    if (subtotal < 100 && subtotal > 50)
    {
    service_charge = net_total * service_charge1;
    total = subtotal + service_charge;
    }
    if (subtotal < 50)
    {
    service_charge = net_total * service_charge2;
    total = subtotal + service_charge;
    }
    //bill display
    outs << " HIGH FASHION DEPARTMENT STORE"<< endl;
    outs << " MONTHLY BILLING STATEMENT" << endl;
    ins >> customer;
    outs << " " << customer << endl;
    outs<<endl<<endl;
    outs << "DEPT NBR " << " ITEM NBR " << " AMOUNT OF PURCHASE " << " DISCOUNT AMOUNT " << " NET AMOUNT " << endl;
    outs <<"---------------------------------------------------------------"<<endl;
    outs << endl;
    outs << department << " " << item << " " << purchase << " " << discount << " " << net << endl;
    if (department == 2)
    {
    outs << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    else
    {
    outs << "TOTAL DEPT 2 " << total_purchase << " " << total_discount << " " << net_total << "*" << endl;
    outs << endl;
    outs << department << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    if (department == 3)
    {
    outs << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    else
    {
    outs << "TOTAL DEPT 3 " << total_purchase << " " << total_discount << " " << net_total << "*" << endl;
    outs << endl;
    outs << department << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    if (department == 4)
    {
    outs << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    else
    {
    outs << "TOTAL DEPT 4 " << total_purchase << " " << total_discount << " " << net_total << "*" << endl;
    outs << endl;
    outs << department << " " << item << " " << purchase << " " << discount << " " << net << endl;
    }
    outs << " NET TOTAL AMOUNT " << net_total << "**" << endl;
    outs << " SALES TAX AT 7% " << SalesTax << endl;
    outs << " SERVICE CHARGE " << service_charge << endl;
    outs << endl;
    outs << "FINAL TOTAL - (PLEASE PAY THIS AMOUNT) " << total << "***" << endl;
    }
    }
    _getch();
    ins.close();
    outs.close();
    }//end program

Interestingly, either you or a classmate of yours posted essentially the same issue some four days ago, under a different username. You might want to view the answers given at that time.

Given what you are saying, I gather that most of the code was given to you by the professor as a 'fill in the blanks' problem (see, mike_2000_17? I told you those sorts of problems are common). What parts in particular did you need to change, and how are the results differing from the output the professor gave? I assume that the main question is the formatting of the output, given the differences in the two screenshots, but is there more to it than that?

Edited 1 Year Ago by Schol-R-LEA

like the output is wrong,for example my output says for final purchase 17 but it should be 150.61.I dont know if the calculations are wrong or the variables are setup wrong?and its suppose to print out more than one customer. Like the input data file i attached has 8 sets of data but they are supposed to be categorized into two outputs one for customer 132 and one for 254 but I can only get the customer 132 to output.

<RANT>
Something has been nagging me about this problem set since it was first brought up, and I think I've figured out what it is: the assignment itself.

It's just a stupid way of doing this. Period.

Seriously, no experienced programmer would solve this problem like that. Ever. This is the sort of thing report generators are for, and report generation has been a solved problem since the 1960s. You would have to be out of your mind to hand-code something like this, because doing so is a terrible waste of time and effort when you could have it done in a fraction of the time with better results using off-the-shelf tools.

I know it is for a class assignment, but that just makes it worse. It is a poorly constructed problem set that teaches all the wrong lessons, and should never have come across any student's desk anywhere. It would make more sense to teach how to design the blasted report generator itself than to teach students to manually write reports, and honestly, just as fast and probably easier on the students.

The professors - and there are many of them - who teach this way are both lazy and incompetent, and should have never have been allowed to set foot in a classroom in an instructor's role. I don't care how good a researcher they are, if they cannot teach in a classroom setting, they shouldn't be required to.

This whole project is symbolic of the horrid pedegogical standards which most colleges have sunk to in this field.
</RANT>

Edited 1 Year Ago by Schol-R-LEA

Comments
So true. This should be a DB and report software
This article has been dead for over six months. Start a new discussion instead.