Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. double number = 0;
  2. int validCheck = 0;
  3. char another = 'y';
  4.  
  5. while(another == 'y')
  6. {
  7. cout<<"Please enter a number: ";
  8. validCheck = scanf("%lf", &number);
  9.  
  10. while (validCheck !=1)
  11. {
  12. cout<<"Invalid input, please enter a number: ";
  13. validCheck = scanf("%lf", &number);
  14. }
  15.  
  16. int c;
  17. do {
  18. c = getchar();
  19. }while(c != 'n' && c != EOF);
  20.  
  21. #include <iostream>
  22. #include <string>
  23.  
  24. using namespace std;
  25.  
  26. int main()
  27. {
  28. double number = 0;
  29. int validCheck = 0;
  30. char another = 'y';
  31. string badinput;
  32.  
  33. while(another == 'y')
  34. {
  35. cout<<"Please enter a number: ";
  36.  
  37.  
  38. while (!(cin >> number))
  39. {
  40. cin.clear();
  41. cin >> badinput;
  42. cout <<"Input " << badinput << " is invalid, please enter a number: ";
  43. }
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement