Files
calorie-calculator/main.go
2024-07-16 17:39:02 +02:00

62 lines
1.4 KiB
Go

package main
import (
"log"
)
func init() {
log.SetFlags(log.Lmicroseconds)
}
type ingredient struct {
weight int
caloriesPer100 int
}
const (
bakingPowder = 92
beans = 100
butter = 717
butter2 = 630 // Cake butter thing that's not real butter
carrots = 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
rice = 130
water = 0
)
func main() {
var ingredients = []ingredient{
{weight: 25, caloriesPer100: sunflowerOil},
{weight: 100, caloriesPer100: onion},
{weight: 16, caloriesPer100: sugar},
{weight: 800, caloriesPer100: cabbage},
}
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)
}