atm959

Text-Based Calculator Made in C#.

Feb 11th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. using System;
  2. using System.Threading;
  3. using System.Text;
  4. using System.Runtime;
  5. using System.Media;
  6. using System.IO;
  7. using System.Net;
  8.  
  9. namespace Simple_Calculator
  10. {
  11.     class Calc
  12.     {
  13.  
  14.         public static String num1String;
  15.         public static String num2String;
  16.         public static double num1;
  17.         public static double num2;
  18.         public static String oper;
  19.         public static String response;
  20.  
  21.         public static void Main (string[] args)
  22.         {
  23.  
  24.             if (args [0] == "-operators") {
  25.  
  26.                 Console.WriteLine ("OPERATORS");
  27.                 Console.WriteLine ("\"+\" - add");
  28.                 Console.WriteLine ("\"-\" - subtract");
  29.                 Console.WriteLine ("\"*\" - multiply");
  30.                 Console.WriteLine ("\"/\" - divide");
  31.                 Console.WriteLine ("\"sin\" - calculate sine (if you use this operator, the second number does not count.)");
  32.                 Console.WriteLine ("\"cos\" - calculate cosine (if you use this operator, the second number does not count.)");
  33.                 Console.WriteLine ("\"%\" - calculate modulo (if you use this operator, the second number does not count.)");
  34.                 Console.WriteLine ("\"log\" - calculate logarithmic math");
  35.                 Console.WriteLine ("\"exp\" - calculate exponents");
  36.                 Console.WriteLine ("\"tan\" - calculate tangents (if you use this operator, the second number does not count.)");
  37.  
  38.             }
  39.  
  40.             Console.WriteLine ("Simple Text-Based Calculator by Aaron Murphy");
  41.             Console.Write ("First Number>> ");
  42.             num1String = Console.ReadLine ();
  43.  
  44.             num1 = Convert.ToInt32 (num1String);
  45.             Console.WriteLine ("");
  46.  
  47.             Console.Write ("Second Number>> ");
  48.             num2String = Console.ReadLine ();
  49.  
  50.             num2 = Convert.ToInt32 (num2String);
  51.             Console.WriteLine ("");
  52.  
  53.             Console.Write ("Operator(+, -, *, /, sin, cos, %, log, exp, and tan)>> ");
  54.             oper = Console.ReadLine ();
  55.             Console.WriteLine ("");
  56.  
  57.             if (oper == "+") {
  58.  
  59.                 Console.WriteLine (num1 + " + " + num2 + " = " + (num1 + num2));
  60.  
  61.             } else if (oper == "-") {
  62.  
  63.                 Console.WriteLine (num1 + " - " + num2 + " = " + (num1 - num2));
  64.  
  65.             } else if (oper == "*") {
  66.  
  67.                 Console.WriteLine (num1 + " * " + num2 + " = " + (num1 * num2));
  68.  
  69.             } else if (oper == "/") {
  70.  
  71.                 Console.WriteLine (num1 + " / " + num2 + " = " + (num1 / num2));
  72.  
  73.             } else if (oper == "sin") {
  74.  
  75.                 Console.WriteLine ("Sin(" + num1 + ") = " + Math.Sin (num1));
  76.  
  77.             } else if (oper == "cos") {
  78.  
  79.                 Console.WriteLine ("");
  80.  
  81.             } else if (oper == "%") {
  82.  
  83.  
  84.  
  85.             } else if (oper == "log") {
  86.  
  87.  
  88.  
  89.             } else if (oper == "exp") {
  90.  
  91.  
  92.  
  93.             } else if (oper == "tan") {
  94.  
  95.  
  96.  
  97.             }
  98.  
  99.             Console.WriteLine ("");
  100.             Console.Write ("Do you want to perform a new calculation(Y/N)?>> ");
  101.             response = Console.ReadLine ();
  102.  
  103.             if (response == "Y" || response == "y") { //It works if the user types "Y" or "y".
  104.  
  105.                 Console.WriteLine ("");
  106.                 Main (null);
  107.  
  108.             }
  109.  
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment