Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter two numbers and choose an operator to perform a calculation");
  14.             Console.WriteLine("---------");
  15.  
  16.             Console.WriteLine("Number one: ");
  17.             double num1 = double.Parse(Console.ReadLine());
  18.  
  19.             Console.WriteLine("Choose the operator: + - * / ^");
  20.             char operator1 = chooseoperator();
  21.  
  22.             Console.WriteLine("Number two: ");
  23.             double num2 = double.Parse(Console.ReadLine());
  24.  
  25.  
  26.  
  27.             double calculationresult = calculation1(num1, num2, operator1);
  28.             displaycalculationresult(calculationresult);
  29.  
  30.         }
  31.  
  32.         static char chooseoperator()
  33.         {
  34.             char operator1 = Console.ReadKey().KeyChar;
  35.             Console.WriteLine();
  36.  
  37.             return operator1;
  38.  
  39.         }
  40.  
  41.         static double calculation1(double num1, double num2, char operator1)
  42.         {
  43.             switch (operator1)
  44.             {
  45.                 case '+':
  46.                     return num1 + num2;
  47.  
  48.                 case '-':
  49.                     return num1 - num2;
  50.  
  51.                 case '*':
  52.                     return num1 * num2;
  53.  
  54.                 case '/':
  55.                     return num1 / num2;
  56.  
  57.                 case '^':
  58.                     return Math.Pow(num1, num2);
  59.  
  60.                 default:
  61.                     return 0;
  62.  
  63.             }
  64.         }
  65.  
  66.         static void displaycalculationresult(double calculationresult)
  67.         {
  68.             Console.WriteLine("The result = " + calculationresult);
  69.             Console.ReadKey();
  70.  
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement