package main import ( "log" ) func init() { log.SetFlags(log.Lmicroseconds) } type ingredient struct { weight int caloriesPer100 int } const ( bakingPowder = 92 beans = 100 butter = 774 butter2 = 630 // Cake butter thing that's not real butter carrot = 35 chickenBreast = 98 cocoa = 363 egg = 150 flour = 338 hotdogs = 250 meatRoll = 210 olives = 151 pastaSauce = 84 peas = 84 postCheese = 78 // Posni sir potato = 86 fatPork = 393 onion = 23 cabbage = 25 sugar = 387 sunflowerOil = 828 tomatoPassata = 21 tomatoPaste = 82 hardCheese = 330 porkLean = 143 rice = 130 water = 0 skyr = 62 vegetableMix = 50 mustard = 30 beetroot = 43 ketchup = 92 sausage = 300 mexicomix = 59 milk = 64 yeast = 185 tofu = 76 sourcream = 70 cherry = 63 lentil = 116 cream = 232 cornstarch = 346 zucchini = 21 chocolate = 516 mistakemeat = 230 haluskymix = 355 ) // tomato 96 // olives 50 func main() { var ingredients = []ingredient{ {253, postCheese}, {400, haluskymix}, {400, water}, {50, egg}, } var totalWeight int64 var totalCalories int64 for _, ingredient := range ingredients { totalWeight += int64(ingredient.weight) totalCalories += int64((ingredient.weight * ingredient.caloriesPer100) / 100) } log.Printf("Total weight: %dg", totalWeight) log.Printf("Total calories: %dcal", totalCalories) log.Printf("Calories per 100g: %dcal", totalCalories*100/totalWeight) }