Thread: How to add a multiply & division buttons???

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2010
    Location
    Philippines
    Posts
    2

    Unhappy How to add a multiply & division buttons???

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace calculator2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            private void txtDisplay_TextChanged(object sender, EventArgs e)
            {
    
            }
            double total1 = 0;
            double total2 = 0;
            double answer;
    
            private void btnOne_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnOne.Text;
            }
            private void btnTwo_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
            }
            private void btnThree_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnThree.Text;
            }
            private void btnFour_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnFour.Text;
            }
            private void btnFive_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnFive.Text;
            }
            private void btnSix_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnSix.Text;
            }
            private void btnSeven_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnSeven.Text;
            }
            private void btnEight_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnEight.Text;
            }
            private void btnNine_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnNine.Text;
            }
            private void btnZero_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnZero.Text;
            }
            private void btnClear_Click(object sender, EventArgs e)
            {
                txtDisplay.Clear();
            }
            private void btnPlus_Click(object sender, EventArgs e)
            {
                total1 = total1 + double.Parse(txtDisplay.Text);
                txtDisplay.Clear();
    
                plusButtonClicked = true;
                minusButtonClicked = false;
                divideButtonClicked = false;
                multiplyButtonClicked = false;
            }
            private void btnEquals_Click(object sender, EventArgs e)
            {
                if (plusButtonClicked == true)
                    
                {
                    total2 = total1 + double.Parse(txtDisplay.Text);
                   
                }
                if (multiplyButtonClicked == true)
                {
                    total2 = total1 * double.Parse(txtDisplay.Text);
                }
                else if (minusButtonClicked == true)
                {
                    total2 = total1 - double.Parse(txtDisplay.Text);
    
                }
                else if (divideButtonClicked == true)
                {
                    total2 = total1 / double.Parse(txtDisplay.Text);
                }
                txtDisplay.Text = total2.ToString();
                total1 = 0;
            }
            private void btnPoint_Click(object sender, EventArgs e)
            {
                txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
            }
            bool plusButtonClicked = false;
            bool minusButtonClicked = false;
            bool divideButtonClicked = false;
            bool multiplyButtonClicked = false;
            private void btnMinus_Click(object sender, EventArgs e)
            {
                total1 = total1 + double.Parse(txtDisplay.Text);
                txtDisplay.Clear();
    
                minusButtonClicked = true;
                plusButtonClicked = false;
                divideButtonClicked = false;
                multiplyButtonClicked = false;
            }
            
            private void btnMultiply_Click(object sender, EventArgs e)
            {
                total1 = total1 / double.Parse(txtDisplay.Text);
                multiplyButtonClicked = true;
                divideButtonClicked = true;
                minusButtonClicked = false;
                plusButtonClicked = false;
                txtDisplay.Clear();
            }
    
            private void btnDivide_Click(object sender, EventArgs e)
            {
                total1 = total1 / double.Parse(txtDisplay.Text);
                multiplyButtonClicked = true;
                divideButtonClicked = true;
                minusButtonClicked = false;
                plusButtonClicked = false;
                txtDisplay.Clear();
               
            }
        }
    }
    Last edited by Salem; 11-08-2010 at 11:44 AM. Reason: Added [code][/code] tags - learn to use them yourself

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Add ON_COMMAND menu button handler
    By kybert in forum Windows Programming
    Replies: 6
    Last Post: 09-15-2002, 07:33 PM
  2. Add and delete functions
    By Ana Val sazi in forum C++ Programming
    Replies: 5
    Last Post: 06-18-2002, 09:59 PM
  3. Cannot add file .c to C++ project
    By ooosawaddee3 in forum C++ Programming
    Replies: 7
    Last Post: 04-08-2002, 11:04 PM
  4. (Ken Fitlike) buttons
    By jdinger in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2002, 01:21 PM
  5. Grouping radio buttons
    By Bazz in forum Windows Programming
    Replies: 1
    Last Post: 08-28-2001, 07:15 AM