because you need to enter 2 newlines before the condition is false.
when you enter just 1, ch will have been read but the program is still waiting for input to the sold parameter.
Only when that's filled as well will loop processing commence.
When at the end of the loop both are found to contain \r the loop will terminate.
When there's only 1 \r, one of the conditions of the while will be false and the other true.
true || false == true as is false || true.
Only false || false results in false.
Run the program in a debugger if you wish to confirm this :)
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
>but y doesnt the "do while" loop terminate upon entering "\r" (enter)
cin's >> operator terminates on whitespace. \r and \n are whitespace, so ch and sold will never have those values, the program will simply sit there waiting for input until it gets something it likes.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>this doesnt help either
ch is a char, but sold isn't. cin doesn't know that they're technically interchangeable and X will fail miserably when read by cin for sold. I think your problem is that you don't have a good idea of what the user interface should be, so you end up floundering about for anything that works, no matter how silly, and you make mistakes.
Humor me and try this: Figure out exactly how you want the user interface to work to the point where you can describe it precisely, with examples. Then we'll go from there. I can guarantee that with the proper design foundation, the program will be much better.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>//sold is an integer typecast as character here then u will not got any warning.
You have no idea what you're talking about, do you?
>//ok try this one
Try it if you want, it won't work, as I explained in detail above. If you had bothered to read it (or even try your own suggestion) then you wouldn't have been stupid enough to suggest something so blatantly incorrect.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
You will not be adding up your total with something like =+ the correct operator is +=
Unless you have to use double return key, I would go with something as simple as t1 and flag down the 't' character to exit the loop.
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417