I am doing some console test program, and I have some normal math operations. Example of part of my code:
if (flagMultiplyDivide.Equals(true))
{
if (currentOperator.Equals('*'))
{
currentNumberDouble = multiplyNumbers(currentNumberString, temporaryNumberString);
if (operatorOnHold.Equals('+'))
{
total += currentNumberDouble;
}
else if (operatorOnHold.Equals('-'))
{
total -= currentNumberDouble;
}
else
{
total = currentNumberDouble;
}
flagMultiplyDivide = false;
}
else if (currentOperator.Equals('/'))
{
currentNumberDouble = divideNumbers(temporaryNumberString, currentNumberString);
if (operatorOnHold.Equals('+'))
{
total += currentNumberDouble;
}
else if (operatorOnHold.Equals('-'))
{
total -= currentNumberDouble;
}
else
{
total = currentNumberDouble;
}
}
}
else if (currentOperator.Equals('+'))
{
if (!numberOnHold.Equals(""))
{
total += Convert.ToDouble(currentNumberString) + Convert.ToDouble(numberOnHold);
}
else
{
total += Convert.ToDouble(currentNumberString);
}
}
else if (currentOperator.Equals('-'))
{
if (!numberOnHold.Equals(""))
{
total -= Convert.ToDouble(currentNumberString) - Convert.ToDouble(numberOnHold);
}
else
{
total -= Convert.ToDouble(currentNumberString);
}
}
return total;
Since it is logical program, I have a lot of conditional statements, and it is easy to lose in code. What is the best practice to code conditional statements in my case? How would you improve my part of code?
What am I doing wrong? I never have a problem to make a working code, but I really want to learn best practice, really. That's why I am here.