Hi I tired posting yesterday but to no avail. This is a really simple code, but can someone help me understand why the cout in the first while loop is not being processed? It becomes processed if I removed the second while loop/if loops, but when they are in the code it refuses to process the
If i understand you question correctly, than no, you always have to input two integers for the program to work. The return 0; is not properly placed. It has to be placed right before the last curly bracket.
But can I ask why the program needs two integers? Shouldn't the first while look take the first integer, then define cnt = 1. Then check if there is a second integer(if there is run the second while loop). If there is not a second integer, shouldn't it ignore the second while loop and the if's then execute the remaining code in the first while loop which is to cout "input"?
I don't understand why the second while loop is overriding the remaining code int the first while loop :S
There are always to integers because the 2nd while loop is inside of the 1st and as there aren't any ifs statements condioning if there is or if there isn't a 2nd integer you'll always have to input 2 integers
Oh, so you're saying that the first while loop runs when the first integer is inputed, then the second while loop will stay active until a second integer is inputted no matter how many times I hit enter, unless I write an if statement to say something like "If input == //no input // // execute command" ?(sorry I have no idea how to write this yet). Well ok, I'll work into that.
But how come it ignores the final cout? It should execute that line once the second while loop is completed no?
But how come it ignores the final cout? It should execute that line once the second while loop is completed no?
The second while loop is only completed when input fails. Are you causing the input to fail? (Entering something other than a number or whitespace, for instance?)
------
It just stores the last integer until I input more data a second time. But even then it still excludes the final didget. I've tried just typing in std::cout << "test";
even then it doesn't want to acknolwedge that there is code after/outside the second while loop.
it remains open, so I'm assuming it's still active on one of the while loops, more than likely the second.
(specifically , i just enter in numbers)
---- Edit ---
Ahhh I see what you mean. Sorry, it probably is like talking to someone from another planet. Ok so the second while loop isn't failing/completing because I haven't set anything to finish it, so the final contents of the first while loop aren't getting a chance to initate.
Great thanks :) I'll try and figure out how to get it to do this now. I appricate the info
Ax7 after I stopped replying yesterday, I messed with your code trying to execute it the way you want to. I'm not going to lie, I'm not able to figure out how to get those last numbers from the input to register.
It be so much easier if you allowed the user to enter a number followed by pressing enter.
Oh that's cool, thanks for giving it a shot sherre02. I'm just learning so I'm not sure what you mean by it being easier by making the user enter the numbers followed by pressing enter.
In the one I've posted that's what you do, or are you meaning doing it individually 1 number/enter at a time? Or somehow defineing enter to be a end value of sorts?
In anycase, so far a way that "works" is to enter in a non-int value after the final integer(cire pointed this out). I don't really know the anatomy of C++ yet so, I'm a bit unsure how to set it up so break out of the second while loop when the final integer has been inputted.