public class CerealMixCalculator
static double CheckInput(string message)
Console.WriteLine(message);
if (double.TryParse(Console.ReadLine(), out wert) && wert >= 0)
Console.WriteLine("Ungültige Eingabe");
static void GetItemNutritionalValues(out double amount, out double kcal, out double fat, out double carbs, out double protein)
amount = CheckInput("Wie viele Gramm wird der Meischung davon beigefügt?");
kcal = CheckInput("Wie viele kcal pro 100g?");
fat = CheckInput("Wie viel Fett pro 100g?");
carbs = CheckInput("Wie viele Kohlenhydrate pro 100g?");
protein = CheckInput("Wie viel Protein pro 100g?");
public static void Main()
double amount1, kcal1, fat1, carbs1, protein1;
double amount2, kcal2, fat2, carbs2, protein2;
double amount3, kcal3, fat3, carbs3, protein3;
Console.WriteLine("Gib den Namen der ersten Zutat ein:");
string Item1 = Console.ReadLine();
GetItemNutritionalValues(out amount1, out kcal1, out fat1, out carbs1, out protein1);
Console.WriteLine("Gib den Namen der zweiten Zutat ein:");
string Item2 = Console.ReadLine();
GetItemNutritionalValues(out amount2, out kcal2, out fat2, out carbs2, out protein2);
Console.WriteLine("Gib den Namen der dritten Zutat ein:");
string Item3 = Console.ReadLine();
GetItemNutritionalValues(out amount3, out kcal3, out fat3, out carbs3, out protein3);
double totalWeight = amount1 + amount2 + amount3;
double totalKcal = (amount1 * kcal1 / 100) + (amount2 * kcal2 / 100) + (amount3 * kcal3 / 100);
double totalFat = (amount1 * fat1 / 100) + (amount2 * fat2 / 100) + (amount3 * fat3 / 100);
double totalCarbs = (amount1 * carbs1 / 100) + (amount2 * carbs2 / 100) + (amount3 * carbs3 / 100);
double totalProtein = (amount1 * protein1 / 100) + (amount2 * protein2 / 100) + (amount3 * protein3 / 100);
Console.WriteLine("\nNährwerte pro 100 Gramm der Mischung, mit den Zutaten {Item1}, {Item2} und {Item3}:");
Console.WriteLine($"Kalorien: {totalKcal / totalWeight * 100:F2} kcal");
Console.WriteLine($"Fett: {totalFat / totalWeight * 100:F2} g");
Console.WriteLine($"Kohlenhydrate: {totalCarbs / totalWeight * 100:F2} g");
Console.WriteLine($"Protein: {totalProtein / totalWeight * 100:F2} g");