//static bool quit = false; static void Main(string[] args) { // int a = int.Parse(Console.ReadLine()); bool isRunning = true; while (!Interface.quit) { MathData mathData = Interface.GetAllValuesFromCustomer(); //int a = Interface.GetValueFromUser("Podaj Pierwsza liczbe"); // if (Interface.quit) // { // Console.WriteLine("Zamykam aplikacje"); // Console.ReadKey(); // return; // } // int b = Interface.GetValueFromUser("Podaj Druga liczbe"); // if (Interface.quit) // { // Console.WriteLine("Zamykam aplikacje"); // Console.ReadKey(); // return; // } // string operations = Interface.GetOperations(); //Console.WriteLine("Podaj rodzaj dzialania czyli : + albo - albo * albo / "); //string operation = Console.ReadLine(); //if (operation == "q") //{ // Console.WriteLine("zamykam aplikacje"); // Console.ReadKey(); // return; //} var sum = Calculations.DoMath(mathData);//moze byc tez var sum = Console.WriteLine(sum); } Console.ReadKey(); //int sum = Add(a,b); //int sum1 = Sub(a, b); //int sum2 = Multilpy(a, b); //double sum3 = Division(a, b); //Console.WriteLine("Podaj rodzaj dzialania czyli : + albo - albo * albo / "); //string operation = Console.ReadLine(); //double sum=0; //////switch //switch (operation) //{ // case "+": // sum = Add(a, b); // break; // case "-": // sum = Sub(a, b); // break; // case "x": // case "*": // sum = Multilpy(a, b); // break; // case "/": // sum = Division(a, b); // break; // default: // Console.WriteLine("nie znaleziono"); // break; //} //else if //if (operation == "-") //{ // sum = Sub(a, b); //} //else if (operation == "+") //{ // sum = Add(a, b); //} //else if (operation == "*") //{ // sum = Multilpy(a, b); //} //else if (operation == "/" ) //{ // sum = Division(a, b); //} //else //{ // Console.WriteLine("Error nie znalazlem dzialania"); //} //Console.WriteLine("wynik to "); //Console.WriteLine(sum); //Console.WriteLine("Suma to " + sum + " Odejmowanie to " + sum1 + " Monzenie to " + sum2 + " Dzielenie to " + sum3); // Console.WriteLine($"Suma to "{ sum } "); Console.ReadLine(); Console.ReadKey();//roznica miedzy line, ze kazdy przycisk zamknie }
static void Main(string[] args) { Console.WriteLine("Calculator App"); for (; ;) { Console.WriteLine(); Console.WriteLine("Select an operator"); Console.WriteLine("1. Add"); Console.WriteLine("2. Subtract"); Console.WriteLine("3. Multiply"); Console.WriteLine("4. Divide"); Console.WriteLine("5. Square Root"); Console.WriteLine("6. Power"); Console.WriteLine("7. Exit"); Console.Write("Operator: "); string response = Console.ReadLine(); if (Int32.TryParse(response, out int selection)) { double answer = -1; Calculations calculations = new Calculations(); switch (selection) { case 1: answer = calculations.Add(); break; case 2: answer = calculations.Subtract(); break; case 3: answer = calculations.Multiply(); break; case 4: answer = calculations.Divide(); break; case 5: answer = calculations.Square(); break; case 6: answer = calculations.Power(); break; case 7: Console.WriteLine("Thanks for using! Goodbye!"); Console.ReadLine(); Environment.Exit(0); break; default: Console.WriteLine("Invalid Entry"); break; } Console.WriteLine($"The answer is {answer}"); } else { Console.WriteLine("Invalid Entry"); } } }
static void Main(string[] args) { Console.Title = "Console calculator"; Console.WriteLine("This is an arithmetic claculator for console commands"); Console.WriteLine("Type 'HELP' to get the list of commands available"); Console.WriteLine("Type 'START' to start the calculation"); Console.WriteLine("To exit at any time type 'EXIT' command"); string cmd; do { Console.Write(":>"); cmd = Console.ReadLine().ToUpper(); //make input as case insensitive switch (cmd) { case "HELP": //help command case here PrintAvailableCommands(); break; case "EXIT": //exit command case here Environment.Exit(0); break; case "START": //start command case here { MathematicalDataContainer data = GetUserInput(); // get user input if (data.CorrrectInput) { if (data.MathOperation == "ADD") { data.Result = Calculations.Add(data.FirstNumber, data.SecondNumber); } else if (data.MathOperation == "SUB") { data.Result = Calculations.Subtract(data.FirstNumber, data.SecondNumber); } else if (data.MathOperation == "MUL") { data.Result = Calculations.Multiply(data.FirstNumber, data.SecondNumber); } else if (data.MathOperation == "DIV") { if (data.SecondNumber == 0) { PrintErrorMessage("Division by zero is not allowed!!"); break; } else { data.Result = Calculations.Divide(data.FirstNumber, data.SecondNumber); } } Console.WriteLine($"The result of the operation is: {data.Result}."); // print results of the calculation } else { PrintErrorMessage("Error!! Incorrect input!!"); // error message for failed input validation } break; } case "CLS": //clear screen command case Console.Clear(); break; default: PrintErrorMessage("Bad command!!"); //default wrong command message break; } }while (cmd.ToUpper() != "EXIT"); //run the screen till exit command typed }