/// <summary> /// method : txt_KeyPress /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="KeyPressEventArgs"/> instance containing the event data.</param> private void txt_KeyPress(object sender, KeyPressEventArgs e) { // If they press the backspace let them. if (e.KeyChar == '\b') { return; } CalcLine calcLine = null; // 1st char in the line if (txtValue.Text.Length == 0) { if (e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '\n') { } else { e.Handled = true; MessageBox.Show("You must enter a +, - or the Enter key as the first value", "Error"); } } else { // Not the first char // Is it a terminating char if (e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '*' || e.KeyChar == '/' || e.KeyChar == '#' || e.KeyChar == '=' || e.KeyChar == '\r') { changed = true; calcLine = new CalcLine(txtValue.Text); calculation.Add(calcLine); // Is is a char that needs to go to the start of the line if (e.KeyChar == '+' || e.KeyChar == '-' || e.KeyChar == '*' || e.KeyChar == '/') { txtValue.Text = e.KeyChar.ToString(); txtValue.Select(1, 1); e.Handled = true; return; } // Is it a subtotal if (e.KeyChar == '#') { calcLine = new CalcLine(Operator.subtotal); calculation.Add(calcLine); } // Is it a total else if (e.KeyChar == '=') { calcLine = new CalcLine(Operator.total); calculation.Add(calcLine); } txtValue.Text = ""; } else if (!char.IsDigit(e.KeyChar)) { e.Handled = true; MessageBox.Show("You must enter a digit or #, +, -, *. /, or =", "Error"); } } }
static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("\nCALCULATOR\n" + "===========\n\n" + "[operand] [operation] [operand]"); } else if (args.Length != 3) { Console.WriteLine("Oh-oh, something is missing, please write again your data\n\n" + "[operand][operation][operand]"); } if (args.Contains("+")) { Console.WriteLine(); Console.WriteLine(Calculation <decimal> .Add(args)); } //else if (args.Contains("/")) //{ // Console.WriteLine(Calculation<double>.Divide(args)); //} //else if (args.Contains("*")) //{ // Calculator<double>.Multiply(args); //} //else if (args.Contains("-")) //{ // Console.WriteLine(Calculation<decimal>.Substract(args)); //} }
static void Main() { int x = 10; int y = 20; int addRes = Calculation.Add(x, y); int subRes = Calculation.Sub(x, y); Console.WriteLine(addRes); Console.WriteLine(subRes); }
static void Main(string[] args) { int num01; int num02; Calculation obj = new Calculation(); //New Logic. Console.WriteLine("Enter the First value to be divided"); num01 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter the Secound value to divided by"); num02 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The Result is: " + obj.Divide(num01, num02)); Console.ReadLine(); // Logic For Addition. Console.WriteLine("Enter the First value to be Added"); num01 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter the Secound value to Added "); num02 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The Result is: " + obj.Add(num01, num02)); Console.ReadLine(); // Losic For substraction. Console.WriteLine("Enter the First value to be Subtacted"); num01 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter the Secound value to Subtracted"); num02 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The Result is: " + obj.Subtract(num01, num02)); Console.ReadLine(); // Logic For multiplication. Console.WriteLine("Enter the First value to be Multiplied"); num01 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter the Secound value to Multiplied "); num02 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("The Result is: " + obj.Multiply(num01, num02)); Console.ReadLine(); //OLd Logic. //Console.WriteLine("Enter the First value to be divided"); //num01 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("enter the Secound value to divided by"); //num02 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("The Result is: " + (num01 / num02)); //Console.ReadLine(); //// Logic For Addition. //Console.WriteLine("Enter the First value to be Added"); //num01 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("enter the Secound value to Added "); //num02 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("The Result is: " + (num01 + num02)); //Console.ReadLine(); //// Losic For substraction. //Console.WriteLine("Enter the First value to be Subtacted"); //num01 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("enter the Secound value to Subtracted"); //num02 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("The Result is: " + (num01 - num02)); ////Console.ReadLine(); //// Logic For multiplication. //Console.WriteLine("Enter the First value to be Multiplied"); //num01 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("enter the Secound value to Multiplied "); //num02 = Convert.ToInt32(Console.ReadLine()); //Console.WriteLine("The Result is: " + (num01 * num02)); //Console.ReadLine(); }