Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Scientific Calculator

0.00/5 (No votes)
11 Mar 2008 1  
Scientific calculator that calculates fibonacci modulo factorial sin cos tan.. you are able to also change background color and color of the buttons
Scientific_Calculator

Introduction

This is a scientific calculator that calculates fibonacci modulo factorial sin cos tan.. you are also able to change the background color and color of the buttons.

Using the Code

// using button number 1
private void button1_Click(object sender, EventArgs e)
{
    but_backspace.Enabled = true;        // number button is clicked, enable backspace
    but_backspace.BackColor = Color.LightCoral; // color button when enabled

    if (isOperation == true)          // if we used an operation clear output
        {textBox_output.Text = "";}   // empty output

    if (tempSign == "Sminus")
        { textBox_output.Text += "-1"; }

    else
        textBox_output.Text += "1";    // add 1 to output
        isOperation = false;           // no operation pressed yet
}

// using addition button
private void button12_Click(object sender, EventArgs e)
{
    if (textBox_output.Text == "")
    { // to prevent exception appearing
    }
    else
    {
        Operations.add(double.Parse(textBox_output.Text));
        textBox_output.Text = Convert.ToString(Operations.getResult());
        isOperation = true; // user pressed an operation
        tempSign = "plus";
    }
}

// factorial method
public static long factorial(long num)
{
    if(num >= 21 || num < 0)
    {
        MessageBox.Show("Enter number between 0 & 20",
        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        return 0;
    }
    else
    {
        if(num <= 1)
            return 1;
        else
            return num * factorial(num - 1); // recursive function
    }
}

History

  • 11th March, 2008: Initial post

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here