i realize they are stupid my professor wants them. This is completely legit asking for help i've spent hours trying to find the problem.
i realize they are stupid my professor wants them. This is completely legit asking for help i've spent hours trying to find the problem.
you havent done anything with 'customer' so why compare its fields? lastName will be empty string (i think) and the two ints will be undefined (likely some random number left over from the memory at that address). this code runs, however there is obviously some logic error. maybe you want a do-while loop? you may need to look over your other loops and consider a do-while loop instead.Code://creates customer of the struct rider; rider customer; //while the infile can be read from while(inFile) { //it will loop and read from the inFile data while the customer data //is not equal to END 0 0 while(!(customer.lastName == "END" && customer.tickets == 0 && customer.time ==0)) {
edit: also instead of while(inFile) use while(inFile.good())
Last edited by nadroj; 04-05-2007 at 11:25 PM.
so then how else am i going to get the customer data to be read in?
works fine, ive tested this loop and printed out what it reads each time and it matches the .dat file. look over your other loopsCode:while(inFile.good()) { //it will loop and read from the inFile data while the customer data //is not equal to END 0 0 do { //here the file will place the correct data for each customer into //the correct variables inFile >> customer.lastName >> customer.tickets >> customer.time; //after the customer in that particular read is done putting it in the //correct variables the customer gets pushed ito arrivals queue arrivals.push(customer); }while(!(customer.lastName == "END" && customer.tickets == 0 && customer.time ==0));
ok so r u saying that the error is somewhere else now? or the program runs completely?
the program still never exists for me. im saying that first do loop is fine (at least the one i tried, as i posted above).
look over the logic of your other loops.. others may need to be changed to do...while loops, maybe not though havent looked them over. also be careful with all of your conditions and using !not, is there a logic error there? must be somewhere down there.
the inifinite loop occurs within this while loop:most likely meaning the condition your checking here isnt right.. is it?Code:while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
Last edited by nadroj; 04-05-2007 at 11:35 PM.
isn't ! the same thing as writing !=? and could you help me identify the loop causing the problem i've spent hours on this and can't see it.
If you also post the example input file which makes it crash for you, then we'd be able to replicate what you're doing.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
example input file was posted little while ago, name it 'riders.dat'is there ever a time where that while loop will be false? let me try and rewrite itHopper 2 1 Torvalds 3 10 Jobs 8 4 Gates 100 100 END 0 0
therefore all 3 of these will never be empty at the same time.. either your checking the wrong condition, or you have some logic error somewhere that is preventing this condition from being true.while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
the above is _always_ true, so:
while(arrivals.empty() == true && line.empty() == true && backIn.empty() == true)
the above is _always_ false, so, removing the '== true', we have:
while(arrivals.empty() && line.empty() && backIn.empty())
the above is _always_ false
your code is somewhat difficult to follow, which is making this difficult to debug.. i would have to print your code and sit down and try and understand it, or read the assignment sheet (if any) to understand what you are _trying_ to do.
Last edited by nadroj; 04-05-2007 at 11:48 PM.
i just want it to loop through while all of the queues still have stuff in them, thats now what that first statement says? I mean how else would i have the loops set up to do what i want? i can't think of a way.
Last edited by DarkDot; 04-05-2007 at 11:51 PM.
it does say that.
your original condition:(in your code/logic) this condition is always true.Code:while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
the above is the same as saying:which is the same as saying:Code:while(!(arrivals.empty() && line.empty() && backIn.empty()))again, this is always true.Code:while(!arrivals.empty() && !line.empty() && !backIn.empty())
what this means is that there is never a time in your code that will make this condition false. arrivals, line, and backin will never be empty.
again, your while loop does say what you want it to, however, it results in an infinite loop. so the condition is never false, so its some logic your doing within this while loop.. somewhere in all those ifs and pops and pushes, which i wont go through and figure out what your supposed to be doing.
re-read your assignment sheet or whatever this is for/from to see what your supposed to do there.
Last edited by nadroj; 04-06-2007 at 12:01 AM.
won't they be empty when all the data is written to the outfile?
Um, nadroj, I think you did not get your De Morgan's theorem correct.
is indeed equivalent toCode:while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true))
But now the above is equivalent to:Code:while(!(arrivals.empty() && line.empty() && backIn.empty()))
Code:while(!arrivals.empty() || !line.empty()|| !backIn.empty())
Last edited by laserlight; 04-06-2007 at 12:11 AM.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
writing data to the outfile has nothign to do with the queues being empty or not, so no, writing as much or as little to the outfile wont make them empty.
again, look at your logic.. heres another one:Code:while(!(arrivals.empty() == true && line.empty() == true && backIn.empty() == true)) { rider transfer = arrivals.front(); // HERE if(!line.empty()) // why check if !line.empty()? you already check whether line.empty() is true or false, which is why this while loop is being executed. { while(transfer.time == clock) { line.push(transfer); arrivals.pop(); } // HERE if(!backIn.empty()) // same as above {...