Answer to Question #287621 in C# for Deepthi

Question #287621

monica has cooked n dishes and collected the data on the level of satisfaction for all the dishes from a guest. the guest returns an array, where the ith element of the array is the liking level of the ith dish. also, the time taken to cook the ith dish is i. like-to-time coefficient of a dish is calculated by multiplying the time taken to cook food with its liking level, i.e., input 2[i]. totally like-to-time coefficient is calculated by summing up all individual coefficients of dishes. you want the total like-to-time coefficient to be maximum. you can also remove some dishes, in which case, a new coefficient is calculated using the left dishes. find the maximum sum of all possible like-to-time coefficients.​


1
Expert's answer
2022-01-15T09:18:54-0500
using System;

namespace Monika
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            int n = 8;
            int[] array = new int[n];
            int coef = 0;
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write($"Please enter a liking level for dishe # {i+1}:  ");
                array[i] = int.Parse(Console.ReadLine());
                coef += (i * array[i]);
            }

            Console.Write($"\nTotal coefficient of likes: {coef}");
            Change(ref array);
            Console.ReadLine();
        }

        static void Change(ref int[] array)
        {
            Console.Write($"\nDo you want to change the coefficient of some dish? Y or N  ");
            int coef = 0;
            string would = Console.ReadLine();
            int choose;
            switch (would)
            {
                case "Y": Console.Write("Please select the number of the dish you want to change: ");
                    choose = int.Parse(Console.ReadLine());
                    Console.Write($"Please enter a liking level for dishe # {choose}:  ");
                    array[choose - 1] = int.Parse(Console.ReadLine()); break;
                case "y": Console.Write("Please select the number of the dish you want to change: ");
                    choose = int.Parse(Console.ReadLine());
                    Console.Write($"Please enter a liking level for dishe # {choose}:  ");
                    array[choose - 1] = int.Parse(Console.ReadLine()); break;
                case "N": Console.Write("Thank You!"); break;
                case "n": Console.Write("Thank You!"); break;
                default: Console.Write("Plaese enter Y or N"); Change(ref array); break;
            }

            for (int i = 0; i < array.Length; i++)
            {
                coef += (i * array[i]);
            }

            Console.Write($"\nTotal coefficient of likes: {coef}");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS