// G. Hagopian--PPP4 ex 6

/*
6. Make a vector holding the ten string values "zero", "one", . . . "nine". Use that in a
program that converts a digit to its corresponding spelled-out value; e.g., the input 7 
gives the output seven. Have the same program, using the same input loop, convert 
spelled-out numbers into their digit form; e.g., the input seven gives the output 7.
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	string choice, numStr;
	int d{};
	vector<string> numeral{ "zero","one","two","three","four","five","six","seven","eight","nine" };
	cout << "Enter 's' to enter the name of a digit or 'd' to enter the digit, 'q' to quit: ";
	do {
		cin >> choice;
	} while (!(choice == "s" || choice == "d" || choice == "q")); // choice != "s" && choice != "d");
	while (choice != "q") {
		/*if (choice == "s") {
			cin >> numStr;
			vector<string>::iterator itr = find(numeral.begin(), numeral.end(), numStr);
			if (itr != numeral.cend())
				cout << numStr << " == " << distance(numeral.begin(), itr) << endl;
			else cout << numStr << " not found.\n";
		}*/
		if (choice == "s") {
			int i{};
			cin >> numStr;
			for (; i < numeral.size(); ++i) {
				if(numeral[i] == numStr) {
					cout  << numStr << " is " << i << endl;
					break;
				}
			}
			if (i == numeral.size()) cout << numStr << " is not one our strings.\n";
		}
		else {
			cin >> d;
			if (d > 9 || d < 0) cout << d << " is not one of the numerals.\n";
			else cout << d << " is " << numeral[d] << endl;
		}
		cout << "Enter 's' to enter the name of a digit or 'd' to enter the digit, 'q' to quit: ";
		do {
			cin >> choice;
		} while (!(choice == "s" || choice == "d" || choice == "q")); // choice != "s" && choice != "d");
	}
}