Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help dealing with Arrays

Status
Not open for further replies.

Kyusaku

Technical User
Feb 20, 2001
26
US
Hello,

I am a first semester C++ student and I was wondering if anyone can help me with my program...I am having problems with it outputing too much data, the program is designed to take in two infiles of data, one is a list of weight and prices. The other one is a list of package dimensions (package #, weight, length, width, and depth) The program is supposed to reject packages that are too big, too long and too heavy (which it does just fine) and accept everything else within the qualifying parameters. However, upon reading the output file, I noticed that it is repeating certain item numbers...example: 1223344556677...and so on...what did I do wrong? Also I found out that the program is supposed to be able to accept an unlimited number of packages and mine will only do 20...how can I fix this. Any help is greatly appreciated...as well as suggestions...you can reply to me your response to MRupright@Juno.com THANK YOU FOR YOUR HELP!!

Link to my program:


Link to source and output file:


 
It sounds like you're doing a cross-product. Which is where for every line in your Weight & price table, you're scanning every line in your dimensions table. So if you have 15 rows in the Weight table and 100 rows in your Dimensions table, you're outputting 1500 rows (instead of the ~100 that you should have).

It sounds like you should:

1) Find out how many rows are in the weight table
2) Dimension an array of that size
3) Read the Weight table from beginning to end, storing the info in your array

Now, for every row in your package table you simply scan the array looking for a match. No match, then the package is rejected (or whatever).

Hope this helps.
Chip H.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top