TERROR TERROR

TERROR TERROR

  • NA
  • 7
  • 1.4k

About to make calculator

Apr 25 2014 8:40 PM
Hello Everyone , i want to help about the calculator ,  i try to design calculator like the calculator with calculator of computer ....
 
The problem is that when try to add more than two numbers for example 5+3+2 ) the result will it 5 , get the last two numbers (3+2) and lost the 5
and the same problem with other operator * , / , - when try to count more than tree numbers ...
 
when i enter two numbers work perfect but there is this problem CAN YOU HELP ME ???
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CalculationNew
{
public partial class Form1 : Form
{
string strFirstNumber;
bool check;
decimal num;
string strOperator;
string strFnumber;
decimal temp;
int i = 0;
public Form1()
{
InitializeComponent();
result.Text = "0";
}
private void button26_Click(object sender, EventArgs e)
{
}
//******************************************************************************************************************************************************
//The purpose of this is to put the numbers in to label called result
//note:is the numbers button
private void button14_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
if ((result.Text == "0") || (check == true))//check if the result is equal zero from the begin if it is then clean the label such as to write the numbers you want
{
result.ResetText(); //reset the label called result
}
Button btnNumbers = (Button)sender;//Use the command such as to use to all numbers from (0 - 9) allow to work public with use Button
result.Text = result.Text + btnNumbers.Text; //store the containts to label called result
num += Convert.ToDecimal(btnNumbers.Text);
check = false;//define this with false such as to if you want after press one operator and you want to write more than one numbers (for example 1*1.5 or 5.2*55555 and so on)
}
}
//********************************************************************************************************************************************************
//the purpose of this is to allow to enter at least one dot (.) in label called result
//++Note:is the dot button
private void button21_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
if (result.Text.Contains("."))
{
return;
}
result.Text += button21.Text;
}
}
//*********************************************************************************************************************************************************
//the purpose of this is to operators (addision ,subtraction , multiplication , division)
//++ Note : is the EqualButton
private void button20_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
Button btnOperator = (Button)sender;
strOperator = btnOperator.Text;
strFnumber = result.Text;
num = Decimal.Parse(result.Text);
check = true;
equestion.Text = equestion.Text + num + " " + strOperator;
// textBox2.Text
}
}
//*******************************************************************************************************************************************************
//the purpose of this is to calculate the total of numbers is the symbol equaland check thee operator
private void button19_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
switch (strOperator)//switch such as to check the operator
{
case "+":
{
num = Convert.ToDecimal(strFnumber) + Convert.ToDecimal(result.Text);//convert the string to decimal such as to calculate the numbers
result.Text = Convert.ToString(num);
} break;
case "-":
{
num =(Convert.ToDecimal(strFnumber) - Convert.ToDecimal(result.Text));//convert the string to decimal such as to calculate the numbers
result.Text = Convert.ToString(num);
} break;
case "/":
{
num = (Convert.ToDecimal(strFnumber) / Convert.ToDecimal(result.Text));//convert the string to decimal such as to calculate the numbers
result.Text = Convert.ToString(num);
} break;
case "*":
{
num = Convert.ToDecimal(strFnumber) * Convert.ToDecimal(result.Text);//convert the string to decimal such as to calculate the numbers
result.Text = Convert.ToString(num);
} break;
default:
break;
}
equestion.Text = " ";//clean the label called equestion
}
}
//******************************************************************************************************************************************************
//The purpose of this is to delete numbers from the begin to the end , (depend , how many numbers you want to delete)
//++note: Button "Backspace"
private void button6_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
if ((result.Text.Length > 0) && (result.Text != "0"))//check if there is at least one number
result.Text = result.Text.Remove(result.Text.Length - 1, 1);//this command delete from the begin to the end of the number
if (result.Text.Length == 0)//check if the lenght
result.Text = "0";
}
}
//*******************************************************************************************************************************************************
//the purpose of this is to reset only the label called result with zero
//++Note : is the button "CE"
private void button16_Click(object sender, EventArgs e)
{
if (result.Text == "Invalid value")
{
result.Text = "0";//reset the label called result
strFnumber = " ";//clear
// num = 0;
equestion.ResetText();//reset the label called equestion
}
if (result.Text!="0") //check if the result is not equal with zero then reset the label called result
result.ResetText();//reset the label called result
if(result.Text=="")//check if the result
result.Text = "0";
textBox1.Text = "";
}
//*************************************************************************************************************************************************
//The purpose of this is to resel all values
//++Note : is the button "C"
private void button15_Click(object sender, EventArgs e)
{
result.Text="0";//reset the label called result
strFnumber = " ";//clear
// num = 0;
textBox1.Text = "";
equestion.ResetText() ;//reset the label called equestion
}
//*************************************************************************************************************************************************
private void button10_Click(object sender, EventArgs e)
{
if (result.Text != "Invalid value")
{
if (Convert.ToDecimal(result.Text) >= 0)
{
double root = Math.Sqrt(Convert.ToDouble(result.Text));
result.Text = Convert.ToString(root);
equestion.Text = "sqrt(" + result.Text + ")" + " " + strOperator;
}
else
{
equestion.Text = "sqrt(" + result.Text + ")";
result.Text = "Invalid value";
}
}
}
private void result_Click(object sender, EventArgs e)
{
}
//****************************************************************************************************************************************************
}
}
 

Answers (6)