Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. double TryDoubleInput(istream &cin)
  2. {
  3. // Function
  4. try
  5. {
  6. // Declaration
  7. double value = 0.0; //holds user input
  8.  
  9. cin >> value; //Takes user input and saves it to "value"
  10. value = TryDoubleInput(cin);
  11.  
  12. if (cin.fail())
  13. {
  14. //ClearInputBuffer(); // reset the cin object and clear the buffer.
  15. throw std::exception; //Throw the exception error
  16. }
  17.  
  18. }
  19. catch(...)
  20. {
  21. cerr << "The number entered was invalid. Terminating program."; // exception error
  22. }
  23. return value;
  24. } // end of TryDoubleInput
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement