#include<iostream>
#include <stdexcept>
#include <limits>
using namespace std;
//This program gets the number of day and the month in the Persian Calendar
//& determines where that date stands in the calendar
int main() {
	cout << "The Position of a Date in the Persian Calendar \n";
	cout << "To exit => Day = 0 and Month = 0 \n\n";
	while (true) {
		try {
			int d, m;
			cout << "Day = ";
			cin >> d;
			if (cin.fail()){
				throw invalid_argument("Error! You have to enter integers!");
			}
			cout << "Month = ";
			cin >> m;
			if (cin.fail()){
				throw invalid_argument("Error! You have to enter integers!");
			}
			if (m==0 && d==0) {
				cout << "The program is terminated. Bye";
				break;
			}
			int p;
			if (m>0 && m<7 && d>0 && d<32) {
				p = (m-1)*31 + d;
				cout << "Position = " << p << endl << endl;
			} else if (m>6 && m<13 && d>0 && d<31) {
				p = 186 + (m-7)*30 + d;
				cout << "Position = " << p << endl << endl;
			} else {
				cout << "Error: You have entered a wrong date! \n\n";
			}
		} catch (const invalid_argument& e){
			cin.clear(); 
            cin.ignore(numeric_limits<streamsize>::max(), '\n'); 
			cout << e.what() << endl << endl;
		}	
	}
	return 0;
}
