Advertisement
Guest User

CODE

a guest
Sep 18th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.92 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.Text;
  7. using System.Windows.Forms;
  8.  
  9. namespace BraydonsCalculator
  10. {
  11.     public partial class Form1 : Form
  12.     {
  13.         string input = string.Empty;                             //String storing user input
  14.         string operand1 = string.Empty;                          //String storing first operand
  15.         string operand2 = string.Empty;                          //string storing second operand
  16.         char operation;                                          //char for operation
  17.         double result = 0.0;                                     //calculated result
  18.  
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void button1_Click(object sender, EventArgs e)
  25.         {
  26.             this.textBox1.Text = "";
  27.             input += "1";
  28.             this.textBox1.Text += input;
  29.         }
  30.  
  31.         private void button2_Click(object sender, EventArgs e)
  32.         {
  33.             this.textBox1.Text = "";
  34.             input += "2";
  35.             this.textBox1.Text += input;
  36.         }
  37.  
  38.         private void button3_Click(object sender, EventArgs e)
  39.         {
  40.             this.textBox1.Text = "";
  41.             input += "3";
  42.             this.textBox1.Text += input;
  43.         }
  44.  
  45.         private void button4_Click(object sender, EventArgs e)
  46.         {
  47.             this.textBox1.Text = "";
  48.             input += "4";
  49.             this.textBox1.Text += input;
  50.         }
  51.  
  52.         private void button5_Click(object sender, EventArgs e)
  53.         {
  54.             this.textBox1.Text = "";
  55.             input += "5";
  56.             this.textBox1.Text += input;
  57.         }
  58.  
  59.         private void button6_Click(object sender, EventArgs e)
  60.         {
  61.             this.textBox1.Text = "";
  62.             input += "6";
  63.             this.textBox1.Text += input;
  64.         }
  65.  
  66.         private void button7_Click(object sender, EventArgs e)
  67.         {
  68.             this.textBox1.Text = "";
  69.             input += "7";
  70.             this.textBox1.Text += input;
  71.         }
  72.  
  73.         private void button8_Click(object sender, EventArgs e)
  74.         {
  75.             this.textBox1.Text = "";
  76.             input += "8";
  77.             this.textBox1.Text += input;
  78.         }
  79.  
  80.         private void button9_Click(object sender, EventArgs e)
  81.         {
  82.             this.textBox1.Text = "";
  83.             input += "9";
  84.             this.textBox1.Text += input;
  85.         }
  86.  
  87.         private void button11_Click(object sender, EventArgs e)
  88.         {
  89.             this.textBox1.Text = "";
  90.             input += "0";
  91.             this.textBox1.Text += input;
  92.         }
  93.  
  94.         private void button10_Click(object sender, EventArgs e)
  95.         {
  96.             this.textBox1.Text = "";
  97.             input += ".";
  98.             this.textBox1.Text += input;
  99.         }
  100.  
  101.         private void button12_Click(object sender, EventArgs e)
  102.         {
  103.             this.textBox1.Text = "";
  104.             this.input = string.Empty;
  105.             this.operand1 = string.Empty;
  106.             this.operand2 = string.Empty;
  107.         }
  108.  
  109.         private void PlusClick_Click(object sender, EventArgs e)
  110.         {
  111.             operand1 = input;
  112.             operation = '+';
  113.             input = string.Empty;
  114.         }
  115.  
  116.         private void ClickMinus_Click(object sender, EventArgs e)
  117.         {
  118.             operand1 = input;
  119.             operation = '-';
  120.             input = string.Empty;
  121.         }
  122.  
  123.         private void clickdivide_Click(object sender, EventArgs e)
  124.         {
  125.             operand1 = input;
  126.             operation = '/';
  127.             input = string.Empty;
  128.         }
  129.  
  130.         private void ClickStar_Click(object sender, EventArgs e)
  131.         {
  132.             operand1 = input;
  133.             operation = '*';
  134.             input = string.Empty;
  135.         }
  136.  
  137.         private void button17_Click(object sender, EventArgs e)
  138.         {
  139.             operand2 = input;
  140.             double num1, num2;
  141.             double.TryParse(operand1, out num1);
  142.             double.TryParse(operand2, out num2);
  143.  
  144.             if (operation == '+')
  145.             {
  146.                 result = num1 + num2;
  147.                 textBox1.Text = result.ToString();
  148.             }
  149.             else if (operation == '-')
  150.             {
  151.                 result = num1 - num2;
  152.                 textBox1.Text = result.ToString();
  153.             }
  154.             else if (operation == '*')
  155.             {
  156.                 result = num1 * num2;
  157.                 textBox1.Text = result.ToString();
  158.             }
  159.             else if (operation == '/')
  160.             {
  161.                 if (num2 != 0)
  162.                 {
  163.                     result = num1 / num2;
  164.                     textBox1.Text = result.ToString();
  165.                 }
  166.                 else
  167.                 {
  168.                     textBox1.Text = "Error DIV/ZERO";
  169.                 }
  170.             }
  171.  
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement