Efe Onah Ojobo

Efe Onah Ojobo

  • NA
  • 32
  • 5.5k

calculator

Sep 7 2015 4:18 AM


Hi  , this is my first code I wrote for the
calculator

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;



 



}



 



 



}



 



    
}



 



    
}



 



   
}




Answers (3)