I'm trying to validate the input of this double price variable. If the input is invalid, i.e. "string" or other non-numeric characters, it goes into an infinite loop filling the console with "Must be new decimal - try again: ". To me the logic reads like it should set tempDbl to a new number, and if it is indeed valid input and is different than book.price, set book.price to the new value and break out of the loop. If not, tempDbl doesn't change and it should loop again. If I enter a valid number like 80.08 it works fine, and if the input is not a number, tempDbl is not set with the new value (which I verified with the debugger - it retains its original value).
When the loop iterates again, it skips the cin >> tempDbl entirely. I set a break point in the loop and stepped through it and it goes right past the cin without accepting input in the console.
Anyone have any tips on how to get this working correctly?
If the input is not a number, then cin enters an error state, which means any subsequent requests for info will simply be ignored. You have to use .clear() to clear the state and then empty the garbage in the buffer.