SHARE
TWEET

Untitled

a guest Jul 21st, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  class Program
  2.     {
  3.         // Define equation operators here
  4.         enum EquationOperator
  5.         {
  6.             none,
  7.             add,
  8.             subtract,
  9.             multiply,
  10.             divide
  11.         }
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             // Instantiate variables here
  16.             int numA;
  17.             int numB;
  18.             EquationOperator equationOperator;
  19.  
  20.             Console.WriteLine("Welcome to the calculator! Please type an operator!");
  21.  
  22.             // Check what operator they entered.
  23.             equationOperator = OperatorSelect(Console.ReadLine());
  24.  
  25.             // For debug purposes.
  26.             Console.WriteLine("The operator you selected was " + equationOperator);
  27.  
  28.             //Throw an error and exit the program if it isn't a proper operator.
  29.             if (equationOperator == EquationOperator.none)
  30.             {
  31.                 Console.WriteLine("That is not a proper operator! Operators are: 'add, subtract, multiply, divide'");
  32.                 Console.ReadKey();
  33.                 return;
  34.             }
  35.             Console.ReadKey();
  36.  
  37.         }
  38.  
  39.         // Check what operator they entered and convert to a proper EquationOperator object.
  40.         // If they don't get one of the cases, return none, which will throw an error.
  41.         static EquationOperator OperatorSelect(string input)
  42.         {
  43.             switch (input)
  44.             {
  45.                 case "add":
  46.                     {
  47.                         return EquationOperator.add;
  48.                     }
  49.                 case "subtract":
  50.                     {
  51.                         return EquationOperator.subtract;
  52.                     }
  53.                 case "multiply":
  54.                     {
  55.                         return EquationOperator.multiply;
  56.                     }
  57.                 case "divide":
  58.                     {
  59.                         return EquationOperator.divide;
  60.                     }
  61.                 default:
  62.                     {
  63.                         return EquationOperator.none;  
  64.                     }
  65.             }
  66.         }
  67.  
  68.  
  69.  
  70.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top