public static void Main() { int first_number; int second_number; string operate; float result; Console.Write("Please enter the first integer: "); first_number = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter the second integer: "); second_number = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter an operator (+, -, /, *): "); Calculator1 c = new Calculator1(); operate = Console.ReadLine(); switch (operate) { case "-": result = c.subtract(first_number, second_number); break; case "+": result = c.add(first_number, second_number); break; case "/": result = c.divide(first_number, second_number); break; case "*": result = c.multiply(first_number, second_number); break; default: result = 0; break; } Console.WriteLine(first_number.ToString() + " " + operate + " " + second_number.ToString() + " = " + result.ToString()); }
public void TestInput() { Calculator1 calc = new Calculator1(); try { int result = calc.Calculate("abcd"); Assert.Fail(); } catch (InvalidOperationException) { } }
static void Main(string[] args) { Calculator1 x = new Calculator1(); int i = 1; do { int number1 = Convert.ToInt32(Console.ReadLine()); string calculate = Console.ReadLine(); if (calculate == "^") { Console.WriteLine(x.Sq(number1)); } else { int number2 = Convert.ToInt32(Console.ReadLine()); if (calculate == "+") { Console.WriteLine(x.Add(number1, number2)); } else if (calculate == "*") { Console.WriteLine(x.Mult(number1, number2)); } else if (calculate == "-") { Console.WriteLine(x.Sub(number1, number2)); } else if (calculate == "/") { Console.WriteLine(x.Div(number1, number2)); } } i++; }while (i < 50); Console.ReadKey(); }
static void Main(string[] args) { char a; String val; int n1, n2, ans; Console.Write("Enter integer: "); val = Console.ReadLine(); n1 = Convert.ToInt32(val); Console.Write("Enter integer: "); val = Console.ReadLine(); n2 = Convert.ToInt32(val); Console.Write("Enter operation: "); val = Console.ReadLine(); a = Convert.ToChar(val); Calculator1 obj = new Calculator1(n1, n2); ans = obj.calci(a); Console.WriteLine("Result is " + ans); }
void DoSumTest(string input, int expected) { Calculator1 calc = new Calculator1(); int result = calc.Calculate(input); Assert.AreEqual(expected, result); }
public void JedenplusJeden() { Calculator1 calc = new Calculator1(); int result = calc.Calculate("1+1"); Assert.AreEqual(2, result); }
public void TestMethod1() { Calculator1 calc = new Calculator1(); }
static void Main(string[] args) { string Welcome = "Welcome to DBS Calculator"; string SelectFunction = "Please select the function you require\n\n" + "1: Addition\n" + "2: Subtraction\n" + "3: Multiplication\n" + "4: Division\n" + "5: Square\n" + "6: Square Root\n" + "7: Cube\n" + "8: Cube Root\n" + "9: Sine\n" + "10: Cosine\n" + "11: ***EXIT***"; string SelectNum1_message = "Please choose your first number"; string SelectNum2_message = "Please choose your second number"; Calculator1 calculator = new Calculator1(); int Exit = 0; Console.WriteLine(Welcome); while (Exit == 0) { Console.WriteLine(SelectFunction); Console.WriteLine(); string string_in = Console.ReadLine(); if (calculator.ValidateInput_Function(string_in) < 0) { Console.WriteLine("Invalid entry. Please select value between 1 - 11"); } int func = calculator.ValidateInput_Function(string_in); if ((func > 0) & (func < 5)) { double numA = 0; double numB = 0; string num_string1 = calculator.Num_Validater(SelectNum1_message); string num_string2 = calculator.Num_Validater(SelectNum2_message); if (num_string1 != "Invalid entry. Please input numbers only") { numA = double.Parse(num_string1); } else { Console.WriteLine("Invalid entry. Please input numbers only"); continue; } if (num_string2 != "Invalid entry. Please input numbers only") { numB = double.Parse(num_string2); } else { Console.WriteLine("Invalid entry. Please input numbers only"); continue; } calculator.FuncImplement(func, numA, numB); } else if ((func > 4) & (func < 11)) { double numA = 0; string num_string1 = calculator.Num_Validater(SelectNum1_message); if (num_string1 != "Invalid entry. Please input numbers only") { numA = double.Parse(num_string1); } else { Console.WriteLine("Invalid entry. Please input numbers only"); continue; } calculator.FuncImplement(func, numA, 0); } else if (func == 11) { calculator.FuncImplement(11, 0, 0); } else { Console.WriteLine(""); } if (func == 11) { Console.WriteLine("Thanks for using our app"); Exit = 1; } Console.ReadLine(); } }
public Calculator() { InitializeComponent(); calc = new Calculator1(); }
static void Main(string[] args) { Calculator1 c1 = new Calculator1(); Console.WriteLine(c1.add(1, 2).ToString()); }