# Digital Calculator

1,304

12

1

## Introduction: Digital Calculator

This instructable will teach you how to make a functional calculator that can add, subtract, divide, multiply, do exponents, square roots, and it even has a reset button!

### Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

## Step 2: Start a New Project

Click File then New Project (or press Ctrl+Shift+N) then click Visual C#, Windows, then click Windows Form Application and name it Calculator.

Your screen should look a little something like this. Next go to the Toolbox and find Label and drag and drop onto the the top left corner of the window labeled Form1 do this 3 times,next click on the first Label then go to where it says Properties and scroll down til you see a box that says Text, click it then type in Num1. Do the the same thing to the next Label except name it Num2, and for the third on name do the exact same thing except name it Result.

Next go to the Toolbox and find TextBox and drag and drop next to the Labels 3 times so it looks like the picture above. Next click on the next to the Label that says Num1TextBox and then click on Properties, scroll down til find a box that says (Name) click it and type in Num1, do this to all the TextBoxes according to which Label they are next to.

## Step 5: Adding the Sum Button

Go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Sum and then go to the (Name) and it sum . Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

`double a, b, c;                                                                           a = Convert.ToDouble (num1.Text);                                                         b = Convert.ToDouble (num2.Text);                                                         c = a + b;                                                                                result.Text = c.ToString ();`

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 6: Adding the Difference Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Difference and then go to the (Name) and it difference. Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

`double a, b, c;                                                                           a = Convert.ToDouble (num1.Text);                                                         b = Convert.ToDouble (num2.Text);                                                         c = a - b;                                                                                result.Text = c.ToString ();`

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 7: Adding the Product Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Product and then go to the (Name) and it product. Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

```double a, b, c;
a = Convert.ToDouble (num1.Text);
b = Convert.ToDouble (num2.Text);
c = a * b;
result.Text = c.ToString ();```

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 8: Adding Quotient Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Quotient and then go to the (Name) and it quotient. Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

```double a, b, c;
a = Convert.ToDouble (num1.Text);
b = Convert.ToDouble (num2.Text);
c = a / b;
result.Text = c.ToString ();```

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 9: Adding Exponent Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Exponent and then go to the (Name) and it exponent Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

```double a, b, c;
a = Convert.ToDouble (num1.Text);
b = Convert.ToDouble (num2.Text);
c = Math.Pow(a, b);
result.Text = c.ToString ();```

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 10: Adding Square Root Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Reset and then go to the (Name) and it reset. Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

```double a, b, c;
a = Convert.ToDouble (num1.Text);
b = Convert.ToDouble (num2.Text);
c = Math.Sqrt(a);
result.Text = c.ToString ();```

Save it by pressing Ctrl+S and run it by pressing F5.

In this operation the contents of Num2 box won't be used so you can leave it empty and it won't matter.

## Step 11: Adding Reset Button

Press Shift-F7 then go to the Toolbox and find the Button and drag and drop it onto the screen and stretch it out then click on and go to the Text box and change what it says to Reset and then go to the (Name) and it reset. Then click on the tab with the lightning bolt and double click on the button that says Click it will change your screen so you will see lines of code.

Type in :

` num1.Text = num2.Text = result.Text = "";`

Save it by pressing Ctrl+S and run it by pressing F5.

## Step 12: Finishing Touches

Scroll down til you see a box named FormBorderStyle and change it to FixSingle, scroll down til you see a box named Text and change it to Calculator, scroll down some more ti you see a box named (Name) and change it to calculator,scroll down til you see a box named Locked and change it to True,scroll down til you see a box named Icon download this image: https://www.dropbox.com/s/griurp73tw3akgk/Calculator-icon18.ico?dl=0 and change the icon to this image, scroll down til you see a box named MaximizedBox and change it to False.

## Step 13: Finshed!

You can download the full source from here: https://www.dropbox.com/sh/pqutktym4hpjhb1/AACdhvBngdlSFVgA8jbmhB85a?dl=0.This calculator doesn't have all the functionality of the built in window's calculator but it is still really cool, plus you made it yourself!

Participated in the
Automation Contest

Participated in the
Coded Creations

152 10K
88 8.2K
199 13K

## Discussions

This looks like a fun project. Thanks for sharing! I hope we see more from you on Instructables in the future.