Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- using namespace std;
- int get_num() {
- int a;
- while (true) {
- cout << "1から10までの数値を入力してください。" << endl;
- for (cin >> a; !cin; cin >> a) {
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- cout << "形式が違います。" << endl;
- }
- if (1 <= a && a <= 10) break;
- }
- return a;
- }
- int main() {
- int a = get_num();
- cout << a << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement