Question: Programming Assignment The I/O streams in C++ contain flags that allow the programmer to determine the state of a stream. Listed here under State flag
Programming Assignment
The I/O streams in C++ contain flags that allow the programmer to determine the state of a stream. Listed here under State flag functions, these functions return true or false depending on the state of the stream. You may have noticed that when you entered in data that was not the correct type the program was asking for, the program acted strangely. This is probably due to the fact that the input stream cin has failed and therefore all parts of the program following automatically fail to read in from cin as well. To prevent this behavior, after the program tries to read data from the user (or any input stream), the programmer can test to ensure the stream didn't fail in extracting the data.
Part 1
For the first part of this assignment, you'll be prompting the user for a series of inputs, one number at a time, and ensuring the user entered in the correct data type.
Start by simply prompting the user to enter an integer value. Once the program has attempted to read the value, check the stream's state. If the stream has gone bad, re-prompt the user for correct input (continuing to do so until the user enters the proper input). Note that if the stream fails to read data from the console, whatever was typed is still in the stream. This input will have to be removed from the stream before prompting the user again, otherwise the stream extraction will fail again.
Print the value the user entered to the screen so that you can see that the expected result was stored in your input variable.
Now repeat the algorithm you implemented above, asking the user to enter a floating-point value. Again, use the state of the stream to determine whether the value was read successfully (and retrying until the user enters the value correctly). Print this floating-point value to the screen for inspection as well.
Be sure you are testing your solution thoroughly; enter not only "good" values, but also interesting "incorrect" values and data types as well.
Hello! I want getting some help of this question :) Thanks for helping me and HAve a nice day :)! The program should be written for C++!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
