Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double TryDoubleInput(istream &cin)
- {
- // Function
- try
- {
- // Declaration
- double value = 0.0; //holds user input
- cin >> value; //Takes user input and saves it to "value"
- value = TryDoubleInput(cin);
- if (cin.fail())
- {
- //ClearInputBuffer(); // reset the cin object and clear the buffer.
- throw std::exception; //Throw the exception error
- }
- }
- catch(...)
- {
- cerr << "The number entered was invalid. Terminating program."; // exception error
- }
- return value;
- } // end of TryDoubleInput
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement