Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. bool read (const string& ageStr, int& age, bool result)
  2. {
  3. cout << ageStr;
  4. cin >> age;
  5. if(cin.fail())
  6. {
  7. cin >> result;
  8. cin.clear();
  9. result = false;
  10. }
  11. else
  12. {
  13. result = true;
  14. }
  15. return result;
  16. }
  17. bool read(const string& gpaStr, double& gpa, bool result)
  18. {
  19. string junk;
  20. cout << gpaStr;
  21. cin >> gpa;
  22. if(cin.fail())
  23. {
  24. cin.clear();
  25. cin >> junk;
  26. result = false;
  27. }
  28. else
  29. {
  30. cin.ignore(1024, '\n');
  31. result = true;
  32. }
  33. return result;
  34. }
  35. bool read(const string& nameStr, string& name, bool result)
  36. {
  37. cout << nameStr;
  38. getline(cin, name);
  39. if(cin.fail())
  40. {
  41. result = true;
  42. }
  43. return result;
  44. }
  45. bool read(char& ch, char dot)
  46. {
  47. cin.get(ch);
  48. if(ch == dot)
  49. {
  50. return false;
  51. }
  52. else
  53. {
  54. return true;
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement