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
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