I was given this as my final project for my C++ Logic course.
1 2 3
My assignment is in the .doc file contained in this link:
http://www.richardgnall.com/mcc/C++ Intro/Assessment/
Screenshots are provided in the .doc file and it is meant to run like the .exe file contained in the link as well.
Here's what i have and I can't test anything else because I am being hit with an infinite loop after creating a file if it doesn't exist and for a reference location for the array..
I'm not getting any infinite loop when I run it. I did however pass a c-string into the fstream.open() calls. Maybe that's a problem, I couldn't even get it to compile before I did that.
Ah, so you actually loaded a file. I can't help you there because I don't know what's in the file. Place some breakpoints at the beginning of the while loop in case 2: and step through it. See what kind of data you're getting and if something's wrong there.
I think the proper way to parse a file isn't while(myFile >> name >> tran) but rather
Hmm, well I just tried it with that file with both methods of parsing the file (with myFile.eof() and without) and they both worked, giving no infinite loop.
Just step through that loop with breakpoints and look at what data you're getting.
I am still having trouble finding the file.. The eof() works but the c_str() causes issues that i cant get around. Instead, it prints off an address, but the infinite loop is gone now.
Sorry for the trouble, but do you mind posting the way you have it coded?
Nothing is being put into them. I just debugged mine and the values from your screenshot ("" and -9.255e61) are the values in the array before you assign them anything. So your code either isn't finding the file (you sure it says "Valid file name"?) or the file is empty.
Put a breakpoint at line 94: cust[i].custName = name; and see if it ever gets hit, disable all other breakpoints. If it does get it but you still get bad output, then there's something wrong with the file. Maybe at some point earlier your program accidentally created a new file records.txt(due to some bug) and overwrote the original one?
What do you mean that the values don't show at all? There is always a value associated with those variables as long as they're in scope, which they should be. When you hover over the variable names or when you check the "Locals" tab in visual studio, you don't see anything for values of "name" and "tran" (when the breakpoint is hit)?
If you really don't see a value then I have no idea, I thought the only time you couldn't see the value would be if they're out of scope. In that case maybe you have some stray/missing brackets somewhere? But that would surely throw a compiler error...no idea.