0
while (!correct)
        {   

            cout << "Please enter an angle value => ";
            cin >> value; //request user to input a value

            if(cin.fail())
            {
                cin.clear();
                while(cin.get() != '\n');
                textcolor(WHITE);
                cout << "Please enter a valid value. "<< endl;
                correct = false;

            }
            else
            {
                cin.ignore();
                correct =true;
            }
        }   

Hi, this is part of the code that I have written.
The purpose of this code is to restrict users to input numbers like 10,10.00 etc,
if they input values like (abc,!$@,etc...) the code will request users to reenter the values.

In order to perform this function( restrict user to input valid valus), I get some tips and guides through forums.

I think is my responsibility to learn and understand what these codes do... since this is the first time I use this code.
can someone briefly explain to me what does these codes mean in the program:
cin.fail() cin.clear() while(cin.get() != '\n') cin.ignore()

Thanks for your guides, I appreciate that!

2
Contributors
1
Reply
19
Views
4 Years
Discussion Span
Last Post by Ancient Dragon
1

You will find the explanation of them all here

while(cin.get() != '\n')

The above is getting characters from the keyboard one at a time until '\n' (Enter key) is reached.

Edited by Ancient Dragon

Votes + Comments
Good link, C++.com - I keep a tab open to it in my browser all the time! :-)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.