#include <iostream>
#include <string>
#include <stdexcept>
#include <limits>
using namespace std;

int main() {
	int num = 0;
	string s;
	size_t pos;
 
	while (true){
		cout << "enter num: ";
		if (!(cin >> s)){
			cin.clear();
			cin.ignore(numeric_limits<streamsize>::max(), '\n');
			cout << "input error, try again" << endl;
		}
		else{
			try{
				num = stoi(s, &pos);
				if (pos != s.size()) throw invalid_argument("");
				if (num > 0){
					break;
				}
				cout << "num must be greater than 0" << endl;
			}
			catch (const exception &){
				cout << "num must be an int" << endl;
			}
		}
	}

	cout << num;
	return 0;
}