Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double number = 0;
- int validCheck = 0;
- char another = 'y';
- while(another == 'y')
- {
- cout<<"Please enter a number: ";
- validCheck = scanf("%lf", &number);
- while (validCheck !=1)
- {
- cout<<"Invalid input, please enter a number: ";
- validCheck = scanf("%lf", &number);
- }
- int c;
- do {
- c = getchar();
- }while(c != 'n' && c != EOF);
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- double number = 0;
- int validCheck = 0;
- char another = 'y';
- string badinput;
- while(another == 'y')
- {
- cout<<"Please enter a number: ";
- while (!(cin >> number))
- {
- cin.clear();
- cin >> badinput;
- cout <<"Input " << badinput << " is invalid, please enter a number: ";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement