Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- // Define equation operators here
- enum EquationOperator
- {
- none,
- add,
- subtract,
- multiply,
- divide
- }
- static void Main(string[] args)
- {
- // Instantiate variables here
- int numA;
- int numB;
- EquationOperator equationOperator;
- Console.WriteLine("Welcome to the calculator! Please type an operator!");
- // Check what operator they entered.
- equationOperator = OperatorSelect(Console.ReadLine());
- // For debug purposes.
- Console.WriteLine("The operator you selected was " + equationOperator);
- //Throw an error and exit the program if it isn't a proper operator.
- if (equationOperator == EquationOperator.none)
- {
- Console.WriteLine("That is not a proper operator! Operators are: 'add, subtract, multiply, divide'");
- Console.ReadKey();
- return;
- }
- Console.ReadKey();
- }
- // Check what operator they entered and convert to a proper EquationOperator object.
- // If they don't get one of the cases, return none, which will throw an error.
- static EquationOperator OperatorSelect(string input)
- {
- switch (input)
- {
- case "add":
- {
- return EquationOperator.add;
- }
- case "subtract":
- {
- return EquationOperator.subtract;
- }
- case "multiply":
- {
- return EquationOperator.multiply;
- }
- case "divide":
- {
- return EquationOperator.divide;
- }
- default:
- {
- return EquationOperator.none;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement