Advertisement
TitanChase

Calculater.cs

Feb 21st, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 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 VisualStudioDisplay
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int one = 0;
  14.             int two = 0;
  15.  
  16.             while (true)
  17.             {
  18.                 printMenu();
  19.                 string input = getInput(false);
  20.                 switch (input)
  21.                 {
  22.                     case "1":
  23.                         print("Enter Number 1: ");
  24.                         one = Convert.ToInt32(getInput());
  25.                         print("Enter Number 2: ");
  26.                         two = Convert.ToInt32(getInput());
  27.                         print("The answer is " + Add(one, two));
  28.                         break;
  29.                     case "2":
  30.                         print("Enter Number 1: ");
  31.                         one = Convert.ToInt32(getInput());
  32.                         print("Enter Number 2: ");
  33.                         two = Convert.ToInt32(getInput());
  34.                         print("The answer is " + Subtract(one, two));
  35.                         break;
  36.                     case "Q":
  37.                     case "q":
  38.                         return;
  39.                 }
  40.             }
  41.         }
  42.  
  43.         static void print(string s)
  44.         {
  45.             Console.WriteLine(s);
  46.         }
  47.  
  48.         static void printMenu()
  49.         {
  50.             print("1. Add");
  51.             print("2. Substract");
  52.             print("Q. Quit");
  53.         }
  54.        
  55.  
  56.         static string getInput(bool line = true)
  57.         {
  58.             if(line)
  59.             {
  60.                 return Console.ReadLine();
  61.             }
  62.             else
  63.             {
  64.                 string input = Console.ReadKey().KeyChar.ToString();
  65.                 Console.WriteLine();
  66.                 return input;
  67.             }
  68.         }
  69.  
  70.         static int Add(int one, int two)
  71.         {
  72.             return one + two;
  73.         }
  74.  
  75.         static int Subtract(int one, int two)
  76.         {
  77.             return one - two;
  78.         }
  79.        
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement