public void Run() { Console.WriteLine("Hello and welcome to the most comprehensive calculator programmed in today's world! Please press enter to continue..."); Console.ReadKey(); Console.Clear(); bool continueRunning = true; while (continueRunning) { Console.WriteLine("Please enter a number..."); string firstNumberAsString = Console.ReadLine(); int parsedNumber = int.Parse(firstNumberAsString); Console.WriteLine("Please enter a second number..."); string secondNumberAsString = Console.ReadLine(); int parsedSecondNumber = int.Parse(secondNumberAsString); Menu(); string response = Console.ReadLine(); int intput = int.Parse(response); int answer = 0; switch (intput) { case 1: answer = _calculatorRepo.AddTwoNumbers(parsedNumber, parsedSecondNumber); break; case 2: answer = _calculatorRepo.SubtractTwoNumbers(parsedNumber, parsedSecondNumber); break; case 3: answer = _calculatorRepo.DivideTwoNumbers(parsedNumber, parsedSecondNumber); break; case 4: answer = _calculatorRepo.MultiplyTwoNumbers(parsedNumber, parsedSecondNumber); break; case 5: continueRunning = false; break; default: break; } Console.WriteLine($"After spending time running around the back here, your answer is {answer}. Press enter when your done looking at this."); Console.ReadKey(); } Console.Clear(); Console.WriteLine("GoodBye."); Console.ReadKey(); }
static void Main(string[] args) { CalculatorRepository _calcRepo = new CalculatorRepository(); decimal x = 0; decimal y = 0; decimal result; char symbol; bool isRunning = true; while (isRunning) { Console.WriteLine("Enter the number for your desired function: \n" + "\t1. Add two numbers\n" + "\t2. Subtract two numbers\n" + "\t3. Multiply two numbers\n" + "\t4. Divide two numbers\n" + "\t5. Get a remainder\n" + "\t6. Exit"); var response = int.Parse(Console.ReadLine()); switch (response) { case 1: symbol = '+'; x = GetFirstValueForCalc(); y = GetSecondValueForCalc(); result = _calcRepo.AddTwoNumbers(x, y); isRunning = PrintResults(x, y, result, symbol); break; case 2: symbol = '-'; x = GetFirstValueForCalc(); y = GetSecondValueForCalc(); result = _calcRepo.SubtractTwoNumbers(x, y); isRunning = PrintResults(x, y, result, symbol); break; case 3: symbol = '*'; x = GetFirstValueForCalc(); y = GetSecondValueForCalc(); result = _calcRepo.MultiplyTwoNumbers(x, y); isRunning = PrintResults(x, y, result, symbol); break; case 4: symbol = '/'; x = GetFirstValueForCalc(); y = GetSecondValueForCalc(); result = _calcRepo.DivideTwoNumbers(x, y); isRunning = PrintResults(x, y, result, symbol); break; case 5: symbol = '%'; x = GetFirstValueForCalc(); y = GetSecondValueForCalc(); result = _calcRepo.GetRemainder(x, y); isRunning = PrintResults(x, y, result, symbol); break; case 6: isRunning = false; break; default: symbol = '+'; decimal[] values = GetValues(); result = _calcRepo.AddMultipleNumbers(values); isRunning = PrintResults(result); break; } } }