Preface

In this chapter we want to write Scientific Calculator program .

_______________________________________________________________________________________________

Process

 The following steps show how to write a advanced Calculator:

1. First, Click New Project in Start Page Or On File Menu .

2. In New Project Dialog , Click Windows On Left Pane And Windows Forms Application On Middle Pane .

3. Change forms layout to this Mode :

 

_______________________________________________________________________________________________

4. Now Declare This Public Variables :

C#Visual Basic
Edit|Remove
decimal num1; 
decimal num2; 
string operation; 

5. Then Add This Method for Number Buttons :

C#Visual Basic
Edit|Remove
private void input(string a) 
{ 
    if (textBox1.Text == "0") 
        textBox1.Text = a; 
    else 
        textBox1.Text += a; 
}

6. Add This Code In Number Buttons(Click Event) :

C#Visual Basic
Edit|Remove
input("(Number Of Button)");

7. Now Add This Code For Operation Buttons(+, -, /, *, ^ And Mod(%)) :

C#Visual Basic
Edit|Remove
num1 = decimal.Parse(textBox1.Text); 
operation = "(Operation For Example "+")"; 
textBox1.Text = "0";

8.Then Add  This Code For Calculation Button(=) :

Visual BasicC#
Edit|Remove
num2 = Decimal.Parse(textBox1.Text) 
''''''''''''''''''''''''''''''''''' 
Select Case operation 
    Case "+" 
        textBox1.Text = (num1 + num2).ToString() 
        Exit Select 
    Case "-" 
        textBox1.Text = (num1 - num2).ToString() 
        Exit Select 
    Case "*" 
        textBox1.Text = (num1 * num2).ToString() 
        Exit Select 
    Case "/" 
        textBox1.Text = (num1 / num2).ToString() 
        Exit Select 
    Case "^" 
        textBox1.Text = (Integer.Parse(num1.ToString()) Xor Integer.Parse(num2.ToString())).ToString() 
        Exit Select 
    Case "%" 
        textBox1.Text = (num1 Mod num2).ToString() 
        Exit Select 
End Select

9. Now Add This Code For Cosine Button :

C#Visual Basic
Edit|Remove
textBox1.Text = (Math.Cos(double.Parse(textBox1.Text))).ToString();

10. Then Add This Code For Sinus Button :

C#Visual Basic
Edit|Remove
textBox1.Text = (Math.Sin(double.Parse(textBox1.Text))).ToString();

11. Now Add This Code For Tangent Button :

C#Visual Basic
Edit|Remove
textBox1.Text = (Math.Tan(double.Parse(textBox1.Text))).ToString();

12. Then Add This Code For Logarithm Button :

C#Visual Basic
Edit|Remove
textBox1.Text = (Math.Log(double.Parse(textBox1.Text))).ToString();

13. Now Add This Code For Factorial Button :

 

C#Visual Basic
Edit|Remove
long f = 1for (long i = 1; i <= long.Parse(textBox1.Text); i++) { f = f * i; } 
textBox1.Text = f.ToString();

14. Then Add This Code For Radical Button :

C#Visual Basic
Edit|Remove
textBox1.Text = (Math.Sqrt(double.Parse(textBox1.Text))).ToString();

good luck  !

_______________________________________________________________________________________________

More Information

My Email-Address is aryanmesgari@outlook.com