Hello! I am reading 2 files into a program, a client list and transaction file. When the Client ID's match, I need to increment the total on the Client list by the amount on the Transaction file. If there is a transaction on the Transaction file that does not match to the Client list, I need to write, "Error - Client not on Master File". Everything is working fine except for the Error records. Every record is getting the error message except for the record on the Client list that isn't on the treansaction file. I have tried multiple things and usually end up in a never ending loop. Here is the data:
Client file:
5 Mike Smith 2098.72
6 Sue Nathan 1234.32
100 Bobby Jones 519.69
125 Sally Mayer 345.74
200 Danny Glover 5623.18
Are you sure your files are all opening correctly? You really should check.
You've told us a little of what you want the program to do, but you haven't told us what the program is actually doing. Please describe the exact problem you are experiencing.
I have a Master Client list with Client ID, Client Name, and amount spent. The Tranaction file has the Client ID and the amount of current transactions. I need to match the 2 files. If there is a match by Client ID, I need to add the amount of the current transaction to the amount spent total and write out the record. If there is a record on the Master Client list that is not on the transaction file, I just need to write out the recorda as is. If there are Client ID's on the Transaction file which are not on the Master Client list, I need to write out "Error - Client ID "#" not in Master File.
Everything is working fine except for the Error file.
no, sadly we are not that far into our studies. I did do some research on this, but would like to keep the program in the scope of what we have learned so far. This is an introduction to programming class.
I did as you suggested and changed the client id to a string. Thank you for that input!
IMO, classes/structures and std::vector along with std::string should be introduced very early in an intro course.
Have you studied arrays? Dynamic memory allocation?
Without std::vector/arrays you need to read at least one of the files over and over, which has probably also not been covered, as re-reading a file is a little more advanced.
My apologies for the lack of response. I am taking 5 classes this summer and working nearly full time. We have studied structure of course, and are just into the chapters on arrays. I thought my question may have a simple solution and come to find out it did. I was missing one line of code.......
anyway, thank you for your time, it is appreciated. I kind of like figuring these things out for myself as it is always a learning experience. With my lack of time it is difficult sometimes.
Are you sure this is all correct? The code won't work if there are multiple transactions for the same client, or if are no transactions for a client. It also assumes that the client IDs are in order in both files, but that's probably a given in the assignment.
As a suggestion, checkout <cstdio> functionality and after the run is complete, rename your 'master' to 'oldmaster' and rename 'newmaster' to 'master'.
Depending, delete 'oldmaster' as a complete cleanup.
Thank you! these are excellent suggestions and very good to learn. In real life, I can see the clean up being very important, so this is a great thing to know. In class, we get penalized greatly if we do not follow the teachers pseudocode to the tee.
It's not about copying this but this might be useful.
There's a problem with it in principle though. In a production system probably beyond the scope of this, you need a way to ensure that item costs already recorded aren't continually added to the total - a bit unfair on the customer. A 'already_totalled' flag for checking on the transaction line would do it.