but the problem for me is that i don't remember how to call the TwoOperandsExpressionAnalyzer method with the correct parameters
here's my code for now
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace BatchCalculator
{
class Program
{
static void Main(string[] args)
{
BatchMathExpression();
Console.ReadKey();
}
static void BatchMathExpression()
{
Console.WriteLine("Input file name...");
string filename = Console.ReadLine();
try
{
string[] buffer = File.ReadAllLines(filename);
foreach (string line in buffer)
{
double result = TwoOperandsExpressionAnalyzer(line,?????);
Console.WriteLine(line + " = " + result.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
static string TwoOperandsExpressionAnalyzer(string expression, ref double[] Operands)
{
try
{
if (Operands.Length != 2)
{
throw new Exception("The size of the Operands Array should be 2");
}
string ExpressionNoSp = Regex.Replace(expression, " ", "");
char[] CharBuffer = ExpressionNoSp.ToCharArray();
// This is a splitter.
bool OperatorDone = false;
string operand = "";
string[] opBuffer = new string[2];
int j = 0;
for (int i = 0; i < CharBuffer.Length; i++)
{
//Check if the Operator is already obtained, No need to
//check it. Also avoid consider the first chracter as operator.
if (i > 0 && !OperatorDone)
{
if (CharBuffer[i] == '-')
{
OperatorDone = true;
operand = "-";
j = 1;
continue;
}
if (CharBuffer[i] == '+')
{
OperatorDone = true;
operand = "+";
j = 1;
continue;
}
if (CharBuffer[i] == '*')
{
OperatorDone = true;
operand = "*";
j = 1;
continue;
}
if (CharBuffer[i] == '/')
{
OperatorDone = true;
operand = "/";
j = 1;
continue;
}
}
// Continue add the charcters stream to operand buffer
//till got the operator, then switch the chracter straem to the next buffer.
opBuffer[j] += CharBuffer[i].ToString();
}
// Convert the charcetr array to double array.
for (int k = 0; k < 2; k++)
{
Operands[k] = Convert.ToDouble(opBuffer[k]);
Console.WriteLine(opBuffer[k]);
}
return operand;
}
catch (Exception)
{
return "BAD";
}
}
}
}
the problem is mainly for me in line 29, and i don't really understand the second parameter of line 41 and line 102
any help will be really appreciated.

New Topic/Question
Reply




MultiQuote





|