Advertisement
SuperLemrick

SuperLemrick's Calculator Source Code

Nov 13th, 2014
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace Calculator
  11. {
  12.     public partial class CalculatorForm : Form
  13.     {
  14.         int firstNum = 0;
  15.         int result = 0;
  16.         bool addButtonFlag = false;
  17.         bool subtractButtonFlag = false;
  18.         bool multiplyButtonFlag = false;
  19.         bool divideButtonFlag = false;
  20.         public CalculatorForm()
  21.         {
  22.             InitializeComponent();
  23.         }
  24.  
  25.         private void One_Click(object sender, EventArgs e)
  26.         {
  27.             InputBox.Text += "1";
  28.         }
  29.  
  30.         private void Two_Click(object sender, EventArgs e)
  31.         {
  32.             InputBox.Text += "2";
  33.         }
  34.  
  35.         private void Three_Click(object sender, EventArgs e)
  36.         {
  37.             InputBox.Text += "3";
  38.         }
  39.  
  40.         private void Four_Click(object sender, EventArgs e)
  41.         {
  42.             InputBox.Text += "4";
  43.         }
  44.  
  45.         private void Five_Click(object sender, EventArgs e)
  46.         {
  47.             InputBox.Text += "5";
  48.         }
  49.  
  50.         private void Six_Click(object sender, EventArgs e)
  51.         {
  52.             InputBox.Text += "6";
  53.         }
  54.  
  55.         private void Seven_Click(object sender, EventArgs e)
  56.         {
  57.             InputBox.Text += "7";
  58.         }
  59.  
  60.         private void Eight_Click(object sender, EventArgs e)
  61.         {
  62.             InputBox.Text += "8";
  63.         }
  64.  
  65.         private void Nine_Click(object sender, EventArgs e)
  66.         {
  67.             InputBox.Text += "9";
  68.         }
  69.  
  70.         private void Zero_Click(object sender, EventArgs e)
  71.         {
  72.             InputBox.Text += "0";
  73.         }
  74.  
  75.         private void ClearEverything_Click(object sender, EventArgs e)
  76.         {
  77.             result = 0;
  78.             firstNum = 0;
  79.             InputBox.Text = "";
  80.             addButtonFlag = false;
  81.             subtractButtonFlag = false;
  82.         }
  83.  
  84.         private void Plus_Click(object sender, EventArgs e)
  85.         {
  86.             if (InputBox.Text != "")
  87.             {
  88.                 firstNum = int.Parse(InputBox.Text);
  89.                 InputBox.Text = "";
  90.                 addButtonFlag = true;
  91.             }
  92.             else
  93.             {
  94.                 MessageBox.Show("You must enter a number!");
  95.             }
  96.         }
  97.  
  98.         private void Minus_Click(object sender, EventArgs e)
  99.         {
  100.             if (InputBox.Text != "")
  101.             {
  102.                 firstNum = int.Parse(InputBox.Text);
  103.                 InputBox.Text = "";
  104.                 subtractButtonFlag = true;
  105.             }
  106.             else
  107.             {
  108.                 MessageBox.Show("You must enter a number!");
  109.             }
  110.         }
  111.  
  112.          private void Multiply_Click(object sender, EventArgs e)
  113.         {
  114.             if (InputBox.Text != "")
  115.             {
  116.                 firstNum = int.Parse(InputBox.Text);
  117.                 InputBox.Text = "";
  118.                 multiplyButtonFlag = true;
  119.             }
  120.             else
  121.             {
  122.                 MessageBox.Show("You must enter a number!");
  123.             }
  124.         }
  125.  
  126.          private void Divide_Click(object sender, EventArgs e)
  127.          {
  128.              if (InputBox.Text != "")
  129.              {
  130.                  firstNum = int.Parse(InputBox.Text);
  131.                  InputBox.Text = "";
  132.                  divideButtonFlag = true;
  133.              }
  134.              else
  135.              {
  136.                  MessageBox.Show("You must enter a number!");
  137.              }
  138.          }
  139.  
  140.         private void Equals_Click(object sender, EventArgs e)
  141.         {
  142.             int secondNum = int.Parse(InputBox.Text);
  143.             {
  144.                 if (InputBox.Text != "")
  145.                 {
  146.                     if (addButtonFlag == true)
  147.  
  148.                         result = firstNum + secondNum;
  149.  
  150.                     else if (subtractButtonFlag == true)
  151.  
  152.                         result = firstNum - secondNum;
  153.  
  154.                     else if (divideButtonFlag == true)
  155.  
  156.                         result = firstNum / secondNum;
  157.  
  158.                     else if (multiplyButtonFlag == true)
  159.  
  160.                         result = firstNum * secondNum;
  161.  
  162.                     InputBox.Text = result.ToString();
  163.                  }
  164.              }
  165.          }
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement