// G. Hagopian -- PPP4 Exercise 5

/*
5. Write a program that performs as a very simple calculator. Your calculator should be able 
to handle the four basic math operations — add, subtract, multiply, and divide — on two input
values. Your program should prompt the user to enter three arguments: two double values and
a character to represent an operation. If the entry arguments are 35.6, 24.1, and '+', 
the program output should be The sum of 35.6 and 24.1 is 59.7. 
*/

#include <iostream>
#include <vector>
#include <string>
using namespace std;

double calculate(double,double,char);
double calculate(string, string, char);

int main() {
	double x{}, y{};
	char op{}, type{};
	string a, b;
	cout << "Enter two floats followed by an operation (+,-,*,/): ";
	cout << "Entering strings or doubles? ('s' or 'd')";
	if(type == 'd')
		while (cin >> x >> y >> op) {
			cout << calculate(x, y, op) << endl;
		}
	else while (cin >> a >> b >> op) {
		cout << calculate(x, y, op) << endl;
	}
}

int number(string numStr) {
	vector<string> numeral{ "zero","one","two","three","four","five","six","seven","eight","nine" };
	for (int i = 0; i < numeral.size(); ++i)
		if (numeral[i] == numStr) return i;
	return -1;
}

double calculate(double x, double y, char op) {
	switch (op) {
	case '+':
		return x + y;
		break;
	case '-':
		return x - y;
		break;
	case '*':
		return x * y;
		break;
	case '/' :
		if (y == 0.) 
			cerr << "Division by zero.";
		return x / y;
		break;
	default:
		cerr << "I don't know that operation.";
		return -1;
	}
}

double calculate(string x, string y, char op) {
	switch (op) {
	case '+':
		return number(x) + number(y);
		break;
	case '-':
		return number(x) - number(y);
		break;
	case '*':
		return number(x) * number(y);
		break;
	case '/':
		if (y == "zero")
			cerr << "Division by zero.";
		return number(x) / number(y);
		break;
	default:
		cerr << "I don't know that operation.";
		return -1;
	}
}