// class contains all mathematical operation-related functions public static string getFinalAns(List <string> input) { // loop through final formatted list // pass numbers and operator into calculate function List <string> formattedList = ProcessInput.formatInput(input); for (int i = 0; i < formattedList.Count; i++) { if (formattedList[i].Equals("^")) { formattedList = calculate(formattedList, i); --i; } } for (int i = 0; i < formattedList.Count; i++) { if (CheckInput.timesDivOrMod(formattedList[i])) { formattedList = calculate(formattedList, i); --i; } } for (int i = 0; i < formattedList.Count; i++) { if (CheckInput.plusOrMinus(formattedList[i])) { formattedList = calculate(formattedList, i); --i; } } return("" + double.Parse(formattedList[0])); }
public static bool divZero(List <string> inputList) { // check whether there is a "division by 0" expression in input List <string> formattedList = ProcessInput.formatInput(inputList); for (int i = 0; i < formattedList.Count; i++) { if ((formattedList[i].Equals("/") || formattedList[i].Equals("%")) && double.Parse(formattedList[i + 1]) == 0) { return(true); } } return(false); }