If statement Function

If statement Function

I am trying to use a function to contain a large if/elseif statement and then simply call the function in the on user input of multiple fields in my form which would allow me to simply edit the function instead of editing every field when I need to make a change. 

My assumption is that this is possible but I'm quite stuck. 

I've written a simple test function using a form object and it seems like it should work but I haven't been able to figure out how to call it. 

Here's the function as I've written it:

  1. float newSale.CalculateGrandTotal(New_Sale newSale)
  2. {
  3. grandTotal = 0.0;
  4.     if (newSale.Type_of_Payment  ==  "Cash/Check")
  5.     {
  6.         grandTotal = (newSale.Price_before_Tax  *  (1  +  newSale.Sales_Tax  /  100)).round(2);
  7.     }
  8. return grandTotal;
  9. }


Will this work as I've written it and how do I call it to simply return 'grandTotal' into 'input.grandTotal'?