Skip to main content

Basic Calculator programmeBasic Calculator programme

In this project I expect to create a basic calculator using visual C#when the time goes on I'm expecting to expand this to a advanced calculator this is the beginning  of that.


The 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 WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
         /*
           First of all we declare 3 decimal type varibles to store the values of
           user input and the final output. by refering the code you can undersatnd
           how they are using in the programme.
         */

        decimal valOne, valTwo,total;
        string store;

        public Form1()
        {
            InitializeComponent();
        }

        private void btnZero_Click(object sender, EventArgs e)
        {
            /*
            This statement inputs the value of the button to the display(TextBox)
            If there olready a number in the display it just entert with that number
            this code is similer to This "txtDisplay.Text=txtDisplay.Text+"0";"
            */
             txtDisplay.Text +="0";
        }

        private void btnOne_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "1";
        }

        private void btnTwo_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "2";
        }

        private void btnThree_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "3";
        }

        private void btnFour_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "4";
        }

        private void btnFive_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "5";
        }

        private void btnSix_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "6";
        }

        private void btnSeven_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "7";
        }

        private void btnEight_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "8";
        }

        private void btnNine_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += "9";
        }

        private void btnPoint_Click(object sender, EventArgs e)
        {
            txtDisplay.Text += ".";
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            txtDisplay.Text = "";
        }

        private void btnEqual_Click(object sender, EventArgs e)
        {
            /*
             When the user click the equal(=)button the event hanlder of the
             button beginss to run.It checks the operator in the varible(store)
             Then parse the value of the disply(txtbox)into the varible(valTwo)
             and perform the relavent mathematical function
            */

            if (store.Equals("+")){
                valTwo = decimal.Parse(txtDisplay.Text);
                total = valOne + valTwo;
                txtDisplay.Text = total.ToString();
            }
               else if (store.Equals("-")){
                   valTwo = decimal.Parse(txtDisplay.Text);
                   total = valOne + valTwo;
                   txtDisplay.Text = total.ToString();
               }
                else   if (store.Equals("-")){
                        valTwo = decimal.Parse(txtDisplay.Text);
                        total = valOne + valTwo;
                        txtDisplay.Text = total.ToString();
                    }
                  else  if (store.Equals("*"))
                    {
                        valTwo = decimal.Parse(txtDisplay.Text);
                        total = valOne + valTwo;
                        txtDisplay.Text = total.ToString();
                    }
                    else  if (store.Equals("/")){
                                valTwo = decimal.Parse(txtDisplay.Text);
                                total = valOne + valTwo;
                                txtDisplay.Text = total.ToString();
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            /*
            when the user click the button the value of the display parse in to the
            ariable(valOne)and clear the dislay and parse the operator to the
            varible(Store) as a String value
            */
            valOne = decimal.Parse(txtDisplay.Text);
            txtDisplay.Text = "";
                store="+";

                 }

        private void btnSubstract_Click(object sender, EventArgs e)
        {
            valOne = decimal.Parse(txtDisplay.Text);
            txtDisplay.Text = "";
            store = "-";
        }

        private void btnMultiply_Click(object sender, EventArgs e)
        {
            valOne = decimal.Parse(txtDisplay.Text);
            txtDisplay.Text = "";
            store = "*";
        }

        private void btnDevide_Click(object sender, EventArgs e)
        {
            valOne = decimal.Parse(txtDisplay.Text);
            txtDisplay.Text = "";
            store = "/";
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

Comments

Popular posts from this blog

Download Facebook or Youtube Videos Without Any Tools

                Have you ever liked a video shared by your friend on facebook and wanted to download it…Well this this tutorial is not only for facebook or youtube instead it can be used for any video streaming website like metacafe,dailymotion,veoh or yahoo videos.There are websites on the internet that will convert your video link into a download link but it has the following drawback

How To Remove “Error Deleting File or Folder”

It is a very common and annoying message that the file or folder you are trying to deleted cannot be deleted or thependrive cannot be removed as it is used by the system.In this tutorial I will show how to remove your pendrive or delete the files and folders if you get such an error.This error has various flavours and it can be of any of the following types:

What is the term Multiplexing in data transmission ?

  Multiplexing is the technique of combining multiple signals into a single signal for transmission over a communication channel. In data transmission, multiplexing allows multiple users to share a single communication channel, maximizing its use and increasing efficiency. There are several types of multiplexing used in data transmission, including: Frequency Division Multiplexing (FDM): This technique divides the available frequency range into multiple non-overlapping sub-channels, each of which can be used by a separate signal. Each signal is modulated onto a separate carrier frequency and combined into a single composite signal for transmission. FDM is commonly used in analog systems, such as radio and television broadcasting. Time Division Multiplexing (TDM): This technique divides the available time into multiple time slots, with each slot dedicated to a separate signal. Each signal is transmitted in its designated time slot, and the signals are interleaved in time to create a com