Validate totalCost

used while loop and ternary