There are at least five (probably more) places in the attached C# program code that could...

90.2K

Verified Solution

Question

Programming

There are at least five (probably more) places in the attachedC# program code that could be optimized. Find at least five thingsin the Program.cs file that can be changed to makethe program as efficient as possible.

  1. List five problems you found with the code (Put your listeither in comments within the code or in a separate Word or textdocument), and then optimize the code in the attached code below tomake it as efficient as possible. The program output must not beaffected by your changes. To the user it should still do everythingit did before your changes provided the user enters validdata.

using System;

namespace COMS_340_L4A
{
class Program
{
static void Main(string[] args)
{
Console.Write(\"How many doughnuts do you need for the firstconvention? \");
int.TryParse(Console.ReadLine(), out int total1);

Console.Write(\"How many doughnuts do you need for the secondconvention? \");
int.TryParse(Console.ReadLine(), out int total2);

int totalDonuts = Calculator.CalculateSum(new int[] { total1,total2 });

Console.WriteLine($\"{ totalDonuts } doughnuts is {Calculator.ConvertToDozen(totalDonuts)} dozen.\");
Console.WriteLine(\"Press Enter to quit...\");
Console.ReadLine();
}
}

static class Calculator
{
static int DOZEN = 12;

public static int CalculateSum(int[] args)
{
int return_value = 0;
foreach (int i in args)
{
return_value += i;
}
return return_value;
}

public static int ConvertToDozen(int total)
{
int dozen = DOZEN;
return total / dozen;
}
}
}

Answer & Explanation Solved by verified expert
3.6 Ratings (574 Votes)
Made a few changes but still works the same there is a slight improvement in the efficiency of the code using System namespace COMS340L4A class Program static void Mainstring args    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students