I broke something, even cin statements not working

Okay, I finally got the support classes and menu up and running.

Then I added a random number generator. I had a bug that basically led to an infinite loop of recursion. I stupidly closed the console window before telling visual studio to stop debugging. Couldn't end or access the process for the program. So I did a complete shutdown and restart of the computer. Checked that I fixed the recursion to not happen and continued.

Now, the program has odd behaviour, where the cin statements get skipped, sometimes the statements will work at first then stop, other times they don't work from the beginning.

This is bad, because I have a menu loop that doesn't exit till the user enters exit, but now doesn't give the option anymore.

The second line of code in the entire program will sometimes be broken, so I'm lost on where to even start looking for potential conflicts.

I can assume it was something I added, but since I added a whole random number generator, and it os obviously a problem stemming from something that acts on the whole program, I have no idea what to look for.

Note, using a breakpoint and stepping through the program, stepping will go through the steps of a cout statement, but does not go through the steps of a cin statement.

I don't know if that is normal, but I doubt it.
Create a new project, move your code in it, try again.
It'll probably be thursday or friday before I get another chance to finish up moving to a new project.

Strangely, letting the new functions compile, but commenting out just the new function calls, removes the problem, despite the fact that the issue can show up before the calls. Rewriting the calls didn't help.
Okay, I ported everything to a new project and still experience the same issue. It is quite puzzling.

Some files show up in the debug output as having been loaded followed by "Cannot find or open the PDB file." The files that show up are, ntdll.dll, kernal32.dll, kenalBase.dll, apphelp.dll, msvcr120d.dll, (the last shows up twice). Of course, these always show up in every project even working ones.

One thing I discovered, even after commenting out all the random number stuff I added, I can enter a number, and if I enter an integer, the program works, but if I enter a float, the program malfunctions. The number I created is a double and with the number generator commented out, it remains unused after creation and entry from the user.

The program now breaks after entering the number.

Last edited on
Cna you post the program and example what means "broken" and "not working"

Cannot find or open the PDB file
That's normal. Debugging symbols are not included in Studio and their absence will not change how program is working

I figured the PDB thing was normal, but it is nice to have that confirmed thanks.

I'm limited in what can be posted due to my phone's limited ability.

However, "broken" in this case means that when the program runs, if I enter a float such as 3.2, then the program skips all following cin statments. If I put in an integer such as 4, than the program runs fine.

Of course this is only after having commented out all the random number generator stuff, with it included, the issue is less predictable.

Note, the number type declared in the program is a double.
Last edited on
Check all input statements in your program. It iseems that you either reading something into int before

Alternatively, you might have locale with comma decimal separator active. Does it breaks if you enter 3,2 ?
I've got only four input statements, only one is an int, the others are doubles. Each input statement is immediately preceded by the creation of the variable that is inputted, save the menu choice variable which has only two input statements.

So, the problematic input is specifically the third input, a double.

I'm not sure what you mean by locale, but decimal works on all my other programs so it can't be settings in visual studio unless they change themselves over nothing, and I'm not using any headers I haven't used before, so I don't think something in the program is changing decimals.

I'll test it my next chance which will be tonight to be sure of course, but I don't see how some random setting I've never heard of can just suddenly change itself without prompting (and since I hardly ever get internet on my laptop, it didn't pick it up in an update.)

I can't c&p but the problematic statement is the last of this block,

cout << "Please enter a range,\n";
double v;
cin>>v;
//commented out use of v
Try to make a minimal compiling example whch reproduces your problem.

Comment literally everything but this part of code and parts nessesary for compiling (headers, main() boilerplate) and check if problem persist. If it disappears, start uncommenting parts until you find line which addition breaks your program. Then comment everything else but problem part and line which breaks that part. If problem disappears, start uncommenting again, etc. until you find smallest possible code reproducing your problem.
Then post it.
Do I need to worry about files that are not called? I created several support classes that I will eventually need, but haven't yet used and are therefore not called upon with the #include command, but they are in the same project, do they affect the final compiled program?

To note, The program compiled and ran fine at before adding this last class which is now completely commented out. In fact, the only change made since the last working version is the block posted above and an identical block, (save that the string literal asks for a different number).

I'll add this to the to do list for tonight, but knowing whether I need to worry about thoses other yet unused classes would be nice to know.
Problem solved.

If a wrong type of input is attempted to ve retrieved from the input stream, it sets off a flag and doesn't take it out if the buffer and some other stuff. So you need to have traps to catch such things, to reset the flags and clear the buffer so that cin statements can once again be used.

This kind if problem can result from trying to put a float into an int or similar.
Topic archived. No new replies allowed.