Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication6
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter two numbers and choose an operator to perform a calculation");
- Console.WriteLine("---------");
- Console.WriteLine("Number one: ");
- double num1 = double.Parse(Console.ReadLine());
- Console.WriteLine("Choose the operator: + - * / ^");
- char operator1 = chooseoperator();
- Console.WriteLine("Number two: ");
- double num2 = double.Parse(Console.ReadLine());
- double calculationresult = calculation1(num1, num2, operator1);
- displaycalculationresult(calculationresult);
- }
- static char chooseoperator()
- {
- char operator1 = Console.ReadKey().KeyChar;
- Console.WriteLine();
- return operator1;
- }
- static double calculation1(double num1, double num2, char operator1)
- {
- switch (operator1)
- {
- case '+':
- return num1 + num2;
- case '-':
- return num1 - num2;
- case '*':
- return num1 * num2;
- case '/':
- return num1 / num2;
- case '^':
- return Math.Pow(num1, num2);
- default:
- return 0;
- }
- }
- static void displaycalculationresult(double calculationresult)
- {
- Console.WriteLine("The result = " + calculationresult);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement