Checking more than 2 variables in a if statement

Hey, I need a way to check all there variables in one if statement so if all of those conditions are correct recipe good = true but its saying that there is a error (Expected a "{" after a if condition). Does anyone know how to fix this?




var recipeGood = false



var egg: Int = 0

var flour: Int = 0

var cocoaPowder: Int = 0

var whiteSugar: Int = 0

var butter: Int = 0

var goldenSyrup: Int = 0

var milk: Int = 0

var bakingSoda: Int = 0

var vanillaEssence: Int = 0

var icingSugar: Int = 0

var water: Int = 0



var egg2: Int = 0

var flour2: Int = 0

var cocoaPowder2: Int = 0

var whiteSugar2: Int = 0

var butter2: Int = 0

var goldenSyrup2: Int = 0

var milk2: Int = 0

var bakingSoda2: Int = 0

var vanillaEssence2: Int = 0

var icingSugar2: Int = 0

var water2: Int = 0



func checkRecipe() {

    if egg >= egg2 && flour >= flour2 $$ cocoaPowder >= cocoaPowder2 $$ whiteSugar >= whiteSugar2 $$ butter >= butter2 $$ goldenSyrup >= goldenSyrup2 $$ milk >= milk2 $$ bakingSoda >= bakingSoda2 $$ vanillaEssence >= vanillaEssence2 $$ icingSugar >= icingSugar2 $$ water >= water2 {

       

        recipeGood = true

        

    }

        

}




You start correctly with && but continue with $$ .

You should make your code more robust:

  • if recipeGood is true on a first test, and you change some value, it may have to turn false.
  • with present code it will remain true.

You could write:

func checkRecipe() {

    recipeGood =  egg >= egg2 && flour >= flour2 && cocoaPowder >= cocoaPowder2 && whiteSugar >= whiteSugar2 && butter >= butter2 && goldenSyrup >= goldenSyrup2 && milk >= milk2 && bakingSoda >= bakingSoda2 && vanillaEssence >= vanillaEssence2 && icingSugar >= icingSugar2 && water >= water2
}

Perhaps use a switch ?

Checking more than 2 variables in a if statement
 
 
Q