Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Adjust the code in C# to produce the output shown below. using System; using Sys

ID: 3717049 • Letter: A

Question

Adjust the code in C# to produce the output shown below.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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(" Daily Averages ");
foreach (double average in dailyAverage)
{
Console.WriteLine(" {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];

for (int i = 0; i < MEALS_IN_DAY; i++)
{
for (int j = 0; j < DAYS_IN_WEEK; j++)
{
totalByMeals += calories[j, i];
}
mealAverage[i] = totalByMeals / DAYS_IN_WEEK;
totalByMeals = 0;
}

return mealAverage;
}//end CalculateAverageByMeal

public static void DisplayMealAverage(double[] mealAverage)
{

Console.WriteLine(" Average per Meal ");
// Output the average number of calories per meal
foreach(double mealAvg in mealAverage)
{
Console.Write(" "+mealAvg + " ");
}
Console.WriteLine(" ");

}//end DisplayMealAverage

public static void DisplayAverageCaloriesPerMeal(int[,] calories)
{
int totalCalories = 0;

// Calculate the total number of calories consumed in a week
for (int i = 0; i < DAYS_IN_WEEK; i++)
{
for (int j = 0; j < MEALS_IN_DAY; j++)
{
totalCalories += calories[i, j];
}
}
Console.WriteLine(" Total Calories consumed in a week is: {0:N2} ", totalCalories);
Console.WriteLine();
double total = 0 ;

// Output the average calories per meal
  
for (int i = 0; i < MEALS_IN_DAY; i++)
{
for (int j = 0; j < DAYS_IN_WEEK; j++)
{
total += calories[j, i];

}
Console.WriteLine(" Average Calories consumed in " + MealsOfDay[i] + " is: {0:N2}", (total / DAYS_IN_WEEK));
Console.WriteLine();
total = 0;
}


}//end DisplayAverageCaloriesPerMeal

static void Welcome()
{
Console.WriteLine(" Welcome to Calorie Counter ");
}//end Welcome

static void ExitProgram()
{
Console.Write("Press enter to exit ...");
Console.ReadLine();
}//end ExitProgram

}//end class
}

Welcome to Calorie Counter Daily Averages Monday Tuesdajy Wednesday1.100 Thursday Friday Saturday Sunday 890 1.333 1,027 967 1.208 1.107 Average per Meal 554 960 1.757 Breakfast Lunch Dinner Average calories 1.090 Press enter to exit ...-

Explanation / Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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(" Daily Averages ");
foreach (double average in dailyAverage)
{
Console.WriteLine(" {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];
for (int i = 0; i < MEALS_IN_DAY; i++)
{
for (int j = 0; j < DAYS_IN_WEEK; j++)
{
totalByMeals += calories[j, i];
}
mealAverage[i] = totalByMeals / DAYS_IN_WEEK;
totalByMeals = 0;
}
return mealAverage;
}//end CalculateAverageByMeal
public static void DisplayMealAverage(double[] mealAverage)
{
Console.WriteLine(" Average per Meal ");
// Output the average number of calories per meal
int i = 0;
foreach(double mealAvg in mealAverage)
{
Console.WriteLine(" {0, -12}: {1, 6:N0} ", MealsOfDay[i++], mealAvg);
}
Console.WriteLine(" ");
}//end DisplayMealAverage
public static void DisplayAverageCaloriesPerMeal(int[,] calories)
{
int totalCalories = 0;
// Calculate the total number of calories consumed in a week
for (int i = 0; i < DAYS_IN_WEEK; i++)
{
for (int j = 0; j < MEALS_IN_DAY; j++)
{
totalCalories += calories[i, j];
}
}
Console.WriteLine(" Average Calories : {0:N2} ", totalCalories/(DAYS_IN_WEEK*MEALS_IN_DAY));
Console.WriteLine();


}//end DisplayAverageCaloriesPerMeal
static void Welcome()
{
Console.WriteLine(" Welcome to Calorie Counter ");
}//end Welcome
static void ExitProgram()
{
Console.Write("Press enter to exit ...");
Console.ReadLine();
}//end ExitProgram
}//end class
}

Output:

Welcome to Calorie Counter


Daily Averages

Monday      :    890

Tuesday     : 1,333

Wednesday   : 1,100

Thursday    : 1,027

Friday      :    967

Saturday    : 1,208

Sunday      : 1,107



Average per Meal

Breakfast   :    553

Lunch       :    960

Dinner      : 1,757



Average Calories : 1,090.00

Press enter to exit ...

Do ask if any doubt. Please upvote.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote