You are on page 1of 3

.

NET ENDSEM LAB


Kolla Bala Seswitha
2000031468
Sec:13

Code:

using System;

namespace FoodCaloriesCalculator
{
class Program
{
static void Main(string[] args)
{
int itemCount = 0;
double totalCalories = 0.0;

while (true)
{
Console.WriteLine("Enter the grams of fat:");
double gramsOfFat = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Enter the grams of carbohydrate:");


double gramsOfCarbs = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter the grams of protein:");
double gramsOfProtein = Convert.ToDouble(Console.ReadLine());

// Calculate the total calories


double fatCalories = gramsOfFat * 9;
double carbCalories = gramsOfCarbs * 4;
double proteinCalories = gramsOfProtein * 4;
double totalCaloriesForItem = fatCalories + carbCalories +
proteinCalories;

// Display the total calories for this item


Console.WriteLine("Total calories for this item: " +
totalCaloriesForItem);

// Update the total calorie and item count


itemCount++;
totalCalories += totalCaloriesForItem;
Console.WriteLine("Total items entered: " + itemCount);
Console.WriteLine("Total calories entered: " + totalCalories);
}
}
}
}

OUTPUTS:

You might also like