-Annie-

Calculator

Feb 2nd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. namespace Calculator
  2. {
  3.     using System;
  4.     using System.IO;
  5.  
  6.     static class Calculator
  7.     {
  8.         static void Main()
  9.         {
  10.             Console.WriteLine("Content-Type: text/html\r\n");
  11.             string htmlContent = File.ReadAllText("../www/calculator.html");
  12.             Console.WriteLine(htmlContent);
  13.             string post = Console.ReadLine();
  14.             if (post != null)
  15.             {
  16.                 string[] postSplited = post.Split(new[] { '&', '=' }, StringSplitOptions.RemoveEmptyEntries);
  17.                 double firstNum = double.Parse(postSplited[1]);
  18.                 string operation = postSplited[3];
  19.                 double secondNum = double.Parse(postSplited[5]);
  20.  
  21.                 switch (operation)
  22.                 {
  23.                     case "%2B": // + sign
  24.                         Console.WriteLine("Result: " + (firstNum + secondNum));
  25.                         break;
  26.                     case "-": // - sign
  27.                         Console.WriteLine("Result: " + (firstNum - secondNum));
  28.                         break;
  29.                     case "*": // * sign
  30.                         Console.WriteLine("Result: " + (firstNum * secondNum));
  31.                         break;
  32.                     case "%2F": // / sign
  33.                         Console.WriteLine("Result: " + (firstNum / secondNum));
  34.                         break;
  35.                     default:
  36.                         Console.WriteLine("Invalid sign!");
  37.                         break;
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment