For the first part of this assignment youll be prompting the
For the first part of this assignment, you\'ll be prompting the user for a series of inputs, 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 second integer 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 second integer 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 as well).
Solution
/*
 The C++ program that prompts a integer value . If integer is inot valid
 then re prompt unitl valid integer is entered. Then prompt for second
 integer and then check if second integer is valid otherwise re prompt
 until valid integer is entered.Print both integers to console
 */
 #include<iostream>
 using namespace std;
int main()
 {
   int num1;
    int num2;
    cout<<\"Enter an integer value :\";
   while(!(cin>>num1))
    {
        //clear cin stream buffer
        cin.clear();
        //ignore any input values including new line
        cin.ignore(999,\'\ \');
        cout<<\"Invalid data type!Please enter integer value :\";
    }
cout<<\"First integer value : \"<<num1<<endl;
   cout<<\"Enter second integer value :\";
    cin>>num2;
    while(!(cin>>num2))
    {
        cin.clear();
        cin.ignore(999,\'\ \');
        cout<<\"Invalid data type!Please enter integer value :\";
    }
cout<<\"Second integer value : \"<<num2<<endl;
   system(\"pause\");
    return 0;
 }
Sample output:

