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

***This must be done in Visual Studio 2010 and use only #include <stdio.h> and #

ID: 3694868 • Letter: #

Question

***This must be done in Visual Studio 2010 and use only #include <stdio.h> and #include stdafx.h***
Write a program to do the following:
Ask the user to enter the number of participants
Use a while loop to ask each participant 3 questions: "Enter the number of calories you ate for breakfast: ", "Enter the number of calories you ate for lunch: ", and "Enter the number of calories you ate for dinner: ". Read in each of these values.
Total the number of calories consumed for the day and print a message to the screen: "You have consumed ## calories today.".
If the total calories is less than or equal to 2000, print another message: "You are within the 2000 calorie limit- good job!" else print "Whoops you are over the calorie limit for the day!".
Don't forget to add a line at the very top: #include "stdafx.h" (needed for Visual Studio software

Explanation / Answer

#include "stdafx.h"
using System;
using static System.Console;

namespace DailyCaloriesCounter
{
public class DailyCaloriesCounter
{
public static void Main()
{
int[] breakfast,lunch,dinner;
int[ , ] calories;
for(int i =0; i<7 ; i++)
{
WriteLine("Enter the number of calories you ate for breakfast:");
breakfast[i]= int.Parse(Console.ReadLine());
WriteLine("Enter the number of calories you ate for lunch: ");
lunch[i] = int.Parse(Console.ReadLine());
WriteLine("Enter the number of calories you ate for dinner:");
dinner[i] = int.Parse(Console.ReadLine());
calories[i,i,i] = {breakfast[i],lunch[i],dinner[i]};
}
double[] dailyAverage = new double[7];
double[] mealAverage = new double[3];
dailyAverage = CalculateAverageByDay(calories);
mealAverage = CalculateAverageByMeal(calories);
ReadyKey();
}
public static double[] CalculateAverageByDay(int[ , ] calories)
{
int sum = 0;
double[] dailyAverage = new double[3];
for (int r=0; r<calories.GetLength(0); r++)
{
for (int c=0; c<calories.GetLength(1); c++)
sum += calories[r,c];
dailyAverage[r] = (double)sum/calories.GetLength(1);
sum = 0;
}
return dailyAverage;
}
public static double[] CalculateAverageByMeal(int[ , ] calories)
{
int sum = 0;
double[] breakfastAverage = new double[3];
for (int c=0; c<calories.GetLength(1); c++)
{
for (int r=0; r<calories.GetLength(0); r+++)
sum += calories[r,c];
breakfastAverage[r] = (double)sum/calories.GetLength(1);
sum = 0;
}
return mealAverage;
}
  
public static void DisplayDailyCaloriesCount(double[] dailyAverage)
{
int dayNumber = 1;
WriteLine("Day Calories Counter");
foreach ( double avgCalories in dailyAverage)
{
WriteLine("Day {0}: {1,6:No}", dayNumber,avgCalories);
dayNumber++;
}
public static void DisplayMealAverage(double[] mealAverage)
{
string[] mealTime = {"Breakfast", "Lunch","Dinner"};
WriteLine(" Meal Average Calories Counter");
for(int c =0 c<mealAverage.Length; c++)
{
WriteLine("{0,-10}:{1,6}", mealTime[c],mealAverage[c].ToString("NO"));
}
}
public static void DisplayAverageCaloriesPerMeal(int[ , ] calories)
{
double sum = 0;
for ( int da = 0; da < calories.GetLength(0); da++)
for(int ml = 0; ml < calories.GetLength(1); m++)
sum += calories[da,ml];
WriteLine(" Calories Average Per Meal: " + "{0:NO}", sum/ calories.Length);
}
}
}