MiroslavKisov

InstructionSet

Oct 6th, 2017
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _16.DebuggingExerciseInstructionSet
  4. {
  5.     class StartUp
  6.     {
  7.         static void Main()
  8.         {
  9.             string opCode = Console.ReadLine().ToUpper();
  10.             long result = 0;
  11.             long operandOne = 0;
  12.             long operandTwo = 0;
  13.             while (opCode != "END")
  14.             {
  15.                 string[] codeArgs = opCode.Split(' ');
  16.  
  17.  
  18.                 switch (codeArgs[0])
  19.                 {
  20.                     case "INC":
  21.                         {
  22.                             operandOne = int.Parse(codeArgs[1]);
  23.                             result = operandOne + 1;
  24.                             Console.WriteLine(result);
  25.                             break;
  26.                         }
  27.                     case "DEC":
  28.                         {
  29.                             operandOne = int.Parse(codeArgs[1]);
  30.                             result = operandOne - 1;
  31.                             Console.WriteLine(result);
  32.                             break;
  33.                         }
  34.                     case "ADD":
  35.                         {
  36.                             operandOne = int.Parse(codeArgs[1]);
  37.                             operandTwo = int.Parse(codeArgs[2]);
  38.                             result = operandOne + operandTwo;
  39.                             Console.WriteLine(result);
  40.                             break;
  41.                         }
  42.                     case "MLA":
  43.                         {
  44.                             operandOne = int.Parse(codeArgs[1]);
  45.                             operandTwo = int.Parse(codeArgs[2]);
  46.                             result = operandOne * operandTwo;
  47.                             Console.WriteLine(result);
  48.                             break;
  49.                         }
  50.                 }
  51.                 opCode = Console.ReadLine().ToUpper();
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment