Simple Calculator

Language

This is a very simple code just like a calculator. The purpose of this code is to teach you how to calculate two number using TextBoxes a ComboBox and a Button. I am using the switch statement and a solution to common problems on how to display integer value to a TextBox.

I decided to upload this because I found some question on the internet regarding on how to convert string to integer as well as how to convert integer to string.
The program contains a very simple code as shown below:

        private void btnCalculate_Click(object sender, EventArgs e)
        {
            int firstno = int.Parse(txtFirstNo.Text);
            int secondno = int.Parse(txtSecondNo.Text);
            int intTotal;

            intTotal = 0;

            switch (cboOperator.Text)
            {
                case "+":
                    intTotal = firstno + secondno;
                    break;
                case "-":
                    intTotal = firstno - secondno;
                    break;
                case "*":
                    intTotal = firstno * secondno;
                    break;
                case "/":
                    intTotal = firstno / secondno;
                    break;
            }

            txtTotal.Text = intTotal.ToString();
        }

The last line here is the most important code. In Visual Basic you don’t need to add ToString() function. But because C# just like c/c++ is very strict you are not allowed to directly display an integer to a TextBox.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

thank you, I'm a beginner on this and it helps a lot to me..

i'm suresh from srilanka.. i done my c+ programing .. but i have not a computer.. but i passed 3 exams . but i can not doing a simle cafe billing system. bcoz i'm very poor. if u can help me how could make a simple cafe billing system. this my humble request.. if u like the send me your personal e mail id. or you can send 4 this detail 2 my e mail address.. [email protected] this is my mail id.

sir good day ask ko lang po if how to backup database table,not a entire database thanks po and more power to this site email nyo naman po sakin [email protected] God bless

Add new comment