public void AddHistory(CurrentOperation item)
        {
            string historyItem = item.fNumber + " " + item.operation + " " + item.sNumber + " = " + item.result;

            sb.AppendLine(historyItem);
            using (var streamWriter = File.CreateText(pathToFile))
            {
                streamWriter.Write(sb.ToString());
            }
        }
示例#2
0
        public void ReadExpression()
        {
            double fNumber = 0, sNumber = 0;
            string symbol = "";

            string line = Console.ReadLine();

            if (line.Equals("EXIT"))
            {
                System.Environment.Exit(-1);
            }
            string[] items;
            items = line.Split(' ');
            try
            {
                if (items.Length != 3)
                {
                    throw new System.FormatException();
                }
                fNumber = Convert.ToDouble(items[0]);
                sNumber = Convert.ToDouble(items[2]);
                symbol  = Convert.ToString(items[1]);
                if (!symbol.Equals("+") && !symbol.Equals("-") && !symbol.Equals("*") && !symbol.Equals("/"))
                {
                    throw new System.FormatException();
                }
            }
            catch (System.FormatException)
            {
                Console.Beep();
                Console.WriteLine("Invalid expression");
                System.Environment.Exit(-1);
            }

            operation = new CurrentOperation(fNumber, sNumber, symbol);
            Reprint();
        }