Simple Calculator
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
hai.
backup database table
Add new comment
- Add new comment
- 1337 views