Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Find and fix the bugs in the following C# program. /* This program computes the average of a student's grades. The expected output is: The
Find and fix the bugs in the following C# program.
/* This program computes the average of a student's grades. The expected output is: The average score is 70 The program has a syntax error (wrongly coded), a specification error (wrongly implemented), and a semantic error (wrong logic). Discuss with the instructor what each of the errors is and why they are wrong. After a response, fix the specification and semantic errors and test to ensure that the program is working as expected. */ using System; namespace IDL3 { public class average { public static void Main(string[] args) { double[] grades = { 90, 80, 70, 60, 50 }; int average = computeAverage(grades); Console.WriteLine("The average score is " + average); } public static double computeAverage(double[] grades) { double average = 0.0; double sum = 0.0; int count = 0; for (int i = 0; i <= grades.Length; ++i) { sum += grades[i]; ++count; average = (average + grades[i]) / 2; } return average; } } }
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