Hello,
i wrote a code for calculating user input,
when ever the user input two "1+2=3"
the result is "3" which is correct .
When the then user want to use that same result to
get another result "+ 5"=8,
but the result will be =6. which is wrong.
so can someone help me out here please
Thanks.
double Operand=0;
String currentOp="";
double operand2=0;
bool iscurrentOperand;
private void btnNumeric_Click(object sender,EventArgs e)
{
Button button=(Button)sender;
txtSow.Text+=button.Text;
iscurrentOp=true;
}
private void btnOperations_Click(object sender,EventArgs e)
{
Button button=(Button)sender;
if (Operand!=0){
operand2=double.Parse(txtSow.Text);
iscurrentOp=true;
switch(currentOp){
case "+":
txtSow.Text=(Operand + operand2).ToString();
break;
case "-":
txtSow.Text=(Operand- operand2).ToString();
break;
case "*":
txtSow.Text=(Operand * operand2).ToString();
break;
}
}
else{
currentOp=button.Text
Operand=Convert.ToDouble(txtSow.Text);
iscurrentOp=true;
}
}
private void btnEqual_Click(object sender,EventArgs e)
{
switch(currentOp)
{
case "+"
txtSow.Text=(Operand + double.Parse(txSow.Text)).ToString();
break;
case "-"
txtSow.Text=(Operand - double.Parse(txSow.Text)).ToString();
break;
case "*"
txtSow.Text=(Operand * double.Parse(txSow.Text)).ToString();
break;
case "/"
txtSow.Text=(Operand / double.Parse(txSow.Text)).ToString();
break;
}
}
}
}
}
Azeem AnzariRank #4,413 · 345 reputationPosted Sep 5, 2015, 9:40 AM EDT
private void btnEqual_Click(object sender,EventArgs e)
{
switch(currentOp)
{
case "+"
txtSow.Text=(Operand + double.Parse(txSow.Text)).ToString();
break;
Raja TRank #685 · 3.5K reputationPosted Sep 5, 2015, 6:10 PM EDT
http://sourcecodeera.com/blogs/Samath/Simple-Calculator-using-C-.aspx
http://m.instructables.com/id/Creating-a-Calculator-Visual-Studio-C/
Efe Onah Ojobo32 reputationPosted Sep 6, 2015, 2:12 AM EDT
Efe Onah Ojobo32 reputationPosted Sep 6, 2015, 2:13 AM EDT
Azeem AnzariRank #4,413 · 345 reputationPosted Sep 6, 2015, 11:18 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Sep 6, 2015, 9:01 PM EDT
Azeem AnzariRank #4,413 · 345 reputationPosted Sep 6, 2015, 9:26 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts