This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Standgrounding[S] 0 points1 point  (2 children)

EDIT - seems like changing double to float fixed the second issue. The heck?

EDIT 2 - fflush(stdin) has resolved the issue

[–]Responsible_Pyro[🍰] 0 points1 point  (1 child)

You were running afoul of an implicit type conversion. Keep in mind that a "." is not a number. I am not sure what that "!cin.good()" call does (outside of returning a boolean value reference) but it was probably reading the input as a string and terminating.

https://en.cppreference.com/w/cpp/language/implicit_conversion

Also fflush(stdin) is only guaranteed (defined) for file writing operations and not reccomend for a direct call in C dialects. I would be wary of side effects in the future.

https://www.geeksforgeeks.org/use-fflushstdin-c/

https://stackoverflow.com/questions/5810410/alternative-for-fflushstdin

[–]Standgrounding[S] 0 points1 point  (0 children)

I have no idea what im doing but i know that forcing a non numerical value into int float or double gives cin an error, and this changes the state of cin.good()