I'm having an issue with my code if someone enters y it works fine but I want to stop multiple entries ie: if someone puts yes or a series of yyyy it should run once and not four times. So I've tried lots of different solutions without success
If you must subscribe to the keyboard-with-free-cat-included school of programming, extract and discard buffered input before attempting the next input.
basically i am just using the first character entered and ignoring the rest.
you can enter as many y as you like and it will only run once.
any other letter entered the program will quit.
Its to stop invalid entries as i build up the code its just the beginning,
Im very new to programming.
If you must subscribe to the keyboard-with-free-cat-included school of programming, extract and discard buffered input before attempting the next input.
Because ambiguous designs like that don't scale very well? If the user wanted to run the program 100 times for example you wouldn't have them type in 'y' that many times. You are far better off prompting them separately and having an embedded loop in which case you certainly would filter the input.
@ OP: Can I propose a slightly different design? How about something closer to how 'ping' works on POSIX systems (the same as "ping -t..." on Windows). Instead of prompting the user and asking if they want to play again, just assume that they do and continue to execute until the app is terminated with 'ctrl+c' which is a standard control combination in shell environments. This eliminates the potentially annoying prompt to the user and marginally simplifies your design loop. If you wanted to be cute about it you could even have the "Thank you for playing" in the destructor of a custom class.
> Instead of prompting the user and asking if they want to play again,
> just assume that they do and continue to execute until the app is terminated with 'ctrl+c'
Using ctrl-c for normal termination of programs is daft to the point of being laughable.
ping (which, by the way, does not have anything to do with POSIX) is a really terrible model for anything other than a purely diagnostic utility, solely used for testing and trouble-shooting.
I don't think it's laughable though, I honestly think that ctrl-c is highly underrated. It's an uncomplicated gesture that is easily remembered and performed, "portable" and it allows for the application to exit normally as opposed to a forced termination. I'll admit that it's outside of convention, but there is no technical reason to discourage it other then the possibility that a simple majority of people may not know about it; but that's what text prompts are for.
Regarding the ping thing (heh that rhymed), MacOS and Linux both continue to run ping until the user tells the application to stop. They do this because the POSIX standard tells them to operate the command line interface in a standardized fashion. Windows does not do this, and someone who is only familiar with Windows and not the other two may assume that the normal operating mode of ping is to send five evenly spaced signals to the target host in which case my example would have been completely lost on them. So I'll grant you that ping in and of itself has nothing to do with POSIX, however I was referring to its behavior on a given platform not the application itself.
I know that you're just quoting the documentation, but for the benefit of anyone else that happens to read this; point-to-point ping floods aren't really an issue on modern hardware specs anymore, not to mention the myriad of settings that are in place by default to negate the attack outright. DoS these days requires more finesse than just screaming at the client.