Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C#..Complete the provided CalorieCounter program. This program reads from a two-dimensional array showing the calories consumed during various meals throughout the week and presents some
C#..Complete the provided CalorieCounter program. This program reads from a two-dimensional array showing the calories consumed during various meals throughout the week and presents some statistics and tables from this data. You are to complete these three methods to get the program working: CalculateAverageByMeal() , DisplayMealAverage() and DisplayAverageCaloriesPerMeal()
When these three methods have been completed, your program should produce the following output:
given the program;
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CalorieCounter { class Program { const int DAYS_IN_WEEK = 7; const int MEALS_IN_DAY = 3; static string[] DaysOfWeek = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; static string[] MealsOfDay = { "Breakfast", "Lunch", "Dinner" }; static void Main(string[] args) { int[,] calories = {{900, 750, 1020 }, {300, 1000, 2700 }, {500, 700, 2100 }, {400, 900, 1780 }, {600, 1200, 1100}, {575, 1150, 1900 }, {600, 1020, 1700 } }; double[] dailyAverage = new double [DAYS_IN_WEEK]; double[] mealAverage = new double[MEALS_IN_DAY]; Welcome(); dailyAverage = CalculateAverageByDay(calories); mealAverage = CalculateAverageByMeal(calories); DisplayDailyAverage(dailyAverage); DisplayMealAverage(mealAverage); DisplayAverageCaloriesPerMeal(calories); ExitProgram(); }//end Main static double [] CalculateAverageByDay(int[,] calories) { int totalByDay = 0; double [] dailyAverage = new double[DAYS_IN_WEEK]; for(int row = 0; row < DAYS_IN_WEEK; row++) { for (int column = 0; column < MEALS_IN_DAY; column++) { totalByDay = totalByDay + calories[row, column]; } dailyAverage[row] = (double) totalByDay / MEALS_IN_DAY; totalByDay = 0; }//end for (int row ...) return dailyAverage; }//end CalculateAverageByDay static void DisplayDailyAverage(double [] dailyAverage) { int dayNumber = 0; Console.WriteLine("\t Daily Averages "); foreach (double average in dailyAverage) { Console.WriteLine("\t{0, -12}: {1, 6:N0} ", DaysOfWeek[dayNumber], average); dayNumber++; }//end foreach }// end DisplayDailyAverage public static double [] CalculateAverageByMeal(int[,] calories) { int totalByMeals = 0; double[] mealAverage = new double[MEALS_IN_DAY]; // Calculate the average number of calories per meal return mealAverage; }//end CalculateAverageByMeal public static void DisplayMealAverage(double [] mealAverage) { Console.WriteLine(" \t Average per Meal "); // Output the average number of calories per meal }//end DisplayMealAverage public static void DisplayAverageCaloriesPerMeal(int[,] calories) { int totalCalories = 0; // Calculate the total number of calories consumed in a week // Output the average calories per meal }//end DisplayAverageCaloriesPerMeal static void Welcome() { Console.WriteLine(" \t Welcome to Calorie Counter "); }//end Welcome static void ExitProgram() { Console.Write("Press enter to exit ..."); Console.ReadLine(); }//end ExitProgram }//end class }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started