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 = 31 tomatoPaste = 82 porkLean = 143 rice = 130 water = 0 skyr = 62 vegetableMix = 50 mustard = 30 ) func main() { var ingredients = []ingredient{ {weight: 1200, caloriesPer100: water}, {weight: 20, caloriesPer100: butter}, {weight: 20, caloriesPer100: flour}, {weight: 20, caloriesPer100: tomatoPaste}, {weight: 700, caloriesPer100: potato}, {weight: 231, caloriesPer100: carrot}, {weight: 500, caloriesPer100: beans}, } 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) }