How do you search & sort an array?
I have two files and I would like to seach them and sort them in any order. My two data files are cust.dat and order.dat.
Code:
Cust.dat contains:
CustomerId
CustomerFirstName
CustomerMiddleName
CustomerLastName
CustomerAddress
CityStateZip
CustomerPhoneNo
CustomerEmailAddress
order.dat contains:
orderId
width
length
CarpetCharge
discount
int NotFound = 0;
While((k < NUM_OF_CUSTOMERS) && (NotFound ==1))
{
if ( searchKey ==custRec[key]customerId)
{
NotFound = 0;
}
if ( searchKey ==orderRec[key]orderId)
{
NotFound = 0;
}
K++;
}
How would I go about sorting it into the fields say CustomerFirstName or by TotalBill?
Thanks for any help you can provide.
Re: based on more than one criteria?
Yes, I belive you understand what I am trying to accomplish.
So, I think that I would need a search to pull it off. I'm just not sure how to do it.
Re: I noticed a lot of hardcode.
The hard coded data is data that will never be changed and it is used to do the calculations.
This program prints a report with the data from cust.dat which
contains the customer information and it gets the data from order.dat and compares the CustomerId and orderId to make sure that the figures match up with the right customer.
Your code is way over my head. I have only learned the basics of "C". You are good at what you do. I'm impressed. I was going through my code this morning and I found the error that you caught plus an error in each scan statement. The CustomerEmailAddress "%25c" is missing in on the customer side and the orderId "%9c is on the order side.
When I compiled it, It printed out the report with CustomerId,
orderId, did not print first, middle, lastName, CustomerAddress,
CityStateZip, CustomerPhoneNo or CustomerEmailAddress.
It printed all of the data from order.dat.
I don't understand why it did not print the rest of the cust.dat...
That's what I am trying to fix at the moment.
Also tell me about some of these calcuations
The whole program is based on a company that sells carpet and installs it.
The first number 10 is the length
The second number 10 or 20 is the width
length and width are read from the data file (not hard coded) and
calculated to get the area ( area = (length * width)
CarpetCharge is read in from the data file and multiplied by area
to get the CarpetTotal ( CarpetTotal = (CarpetCharge * area).
Labor is fixed so it is hard coded
laborTotal = ( .35 * 2000)
installedPrice is CarpetTotal + LaborTotal
discount is read from the file (0.20)
discountTotal = (installedPrice * discount)
subTotal = installedTotal - discountTotal
tax is fixed at 8.5% or .085
tax = TAX * subTotal
total = subTotal + tax
Code:
This is what the original report looks like: I think that it will help you to understand what I am speaking of.
The reports that I have to do:
1 will look like this
1 sorted by CustomerName so I take it as first middle and last.
1 by sorted by total
1 history sorted by CustomerName
1 history sorted by total
and so on
After I figure all of this out, I have to make menus.
I hope this makes more since now.
------------------------------------------------------------------------------------
Header Here
-------------------------------------------------------------------------------------
Customer Id: 123456789
Order Id: 123456789
First Name: James //this is not being filled
Middle Name: William //this is not being filled
Last Name: Madison //this is not being filled
Address: 123 Maddison AVE //this is not being filled
Maddison GA 30000 //this is not being filled
Phone No: (333) 123-1234 //this is not being filled
Email Address: [email protected] //this is not being filled
------------------------------------------------------------------------------------
MEASUREMENT
Length 10ft
Width 20ft
Area 200ft
CHARGES
DESCRIPTION COST/SQ.FT. CHARGE/ROOM
____________ __________ ______________
Carpet $10.00 $2000.00
Labor .35 $70.00
________________
Installed Price $2070.00
Discount 0.20% 414.00
________________
Subtotal $1656.00
Tax $140.76
Total $1796.76