I need help with getting the solution to this C# ProgrammingAssignment. Although the code that I wrote in the first pictureabove had no errors while running it, when I turned it in throughthe Task Check, it gave me 3 error messages. The messages are shownbelow the first picture.
Programming Exercise 8-6 Instructions = |././ Î Write a program named Averages that includes a method named Average that accepts any number of numeric parameters, displays them, and displays their average. For example, if 7 and 4 were passed to the method, the output would be: 74 Average is 5.5 Test your function in your Main() . Tests will be run against Average) to determine that it works correctly when passed one, two, or three numbers, or an array of numbers. Grading When you have completed your program, click the Submit button to record your score. Averages.cs 1 using System; 2 using static System.Console; 3 public class Averages 4 { 5 6 7 8 9 10 11 BAZAAAAAAHH 12 23456 13 14 15 17 18 19 20 } 16 public static void Main() { 21 + 22 } 23} public static void Average(params double[] arr) { 24 double average = 0; for (int i { = = 0; i < arr.Length; ++i) Write(arr + "); average += arr; } average / arr.Length; WriteLine("-- Average is + average); Average (7); Average (7, 4); Average (7, 4, 9); Average(new double[] {7, 1, 4, 9, 3});
Unit TestIncomplete Method Average can average two numbers Build Status Build Succeeded Test Output NUnit Console Runner 3.10.0 (.NET 2.0) Copyright (c) 2019 Charlie Poole, Rob Prouse Tuesday, 05 July 2022 18:45:19 Runtime Environment OS Version: Linux 5.0.0.27 CLR Version: 4.0.30319.42000 Test Files NtTest5751af43.dll Errors, Failures and Warnings 1) Failed: Average TwoNumbers Test.Average Test Expected the average of 8 and 10 to be 9 Expected string length 21 but was 20. Strings differ index 5. Expected: "8 10 -- Average is 9" But was: "8 10 -- Average is 9" at AverageTwoNumbers Test.Average Test () [0x00000] in <065fac3f52e94b37a322a0f62c70dcea>:0 Run Settings DisposeRunners: True WorkDirectory: /root/sandbox5e64cca5 ImageRuntime Version: 4.0.30319 ImageRequiresX86: False ImageRequiresDefaultAppDomainAssemblyResolver: False NumberOfTestWorkers: 2 Test Run Summary Overall result: Failed Test Count: 1, Passed: 0, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0 Failed Tests Failures: 1, Errors:0, Invalid: 0 Start time: 2022-07-05 18:45:20Z End time: 2022-07-05 18:45:21Z Duration: 1.022 seconds Test Contents [TestFixture] public class Average TwoNumbers Test { [Test] public void Average Test) ( using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); Averages.Average(8, 10); string expected = "8 10 -- Average is 9"; Assert.AreEqual(expected, sw.ToString().Trim(), "Expected the average of 8 and 10 to be 9"); }
Unit TestIncomplete Method Average can average three numbers Build Status Build Succeeded Test Output NUnit Console Runner 3.10.0 (.NET 2.0) Copyright (c) 2019 Charlie Poole, Rob Prouse Tuesday, 05 July 2022 18:45:22 Runtime Environment OS Version: Linux 5.0.0.27 CLR Version: 4.0.30319.42000 Test Files NtTest12d1696b.dll Errors, Failures and Warnings 1) Failed: Average ThreeNumbers Test.Average Test Expected the average of 22.3, 44.5, and 88.1 to be 51.6333333333333 Expected string length 46 but was 45. Strings differ at index 15. Expected: "22.3 44.5 88.1 -- Average is 51.6333333333333" But was: "22.3 44.5 88.1 -- Average is 51.6333333333333" at Average ThreeNumbers Test.Average Test () [0x00000] in <ef002b140904491991297cdc08b34f98>:0 Run Settings DisposeRunners: True WorkDirectory: /root/sandbox5e64cca5 ImageRuntimeVersion: 4.0.30319 ImageRequiresX86: False ImageRequires Default AppDomainAssembly Resolver: False ………………^ NumberOfTestWorkers: 2 Test Run Summary Overall result: Failed Test Count: 1, Passed: 0, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0 Failed Tests - Failures: 1, Errors: 0, Invalid: 0 Start time: 2022-07-05 18:45:23Z End time: 2022-07-05 18:45:24Z Duration: 1.036 seconds Test Contents [TestFixture] public class Average ThreeNumbers Test ( [Test] public void Average Test ( using (StringWriter sw = new StringWriter()) { } } Console.SetOut (sw); Averages.Average(22.3, 44.5, 88.1); string expected = "22.3 44.5 88.1 -- Average is 51.6333333333333"; Assert.AreEqual(expected, sw.ToString().Trim(), "Expected the average of 22.3, 44.5, and 88.1 to be 51.6333333333333");
Unit Testincomplete Method Average can average an array of numbers Build Status Build Succeeded Test Output NUnit Console Runner 3.10.0 (.NET 2.0) Copyright (c) 2019 Charlie Poole, Rob Prouse. Tuesday, 05 July 2022 18:45:25 Runtime Environment OS Version: Linux 5.0.0.27 CLR Version: 4.0.30319.42000 Test Files NtTest713801ca.dll Errors, Failures and Warnings 1) Failed: AverageArrayTest.Average Test Expected the average of 3, 4, 5, 6, 7, and 8 to be 5.5 Expected string length 30 but was 29. Strings differ at index 12. Expected: "3 4 5 6 7 8 -- Average is 5.5" But was: "3 4 5 6 7 8 -- Average is 5.5" at AverageArrayTest.Average Test () [0x00000] in <1956ea90e989406f9ed8f5bde3176e76>:0 Run Settings DisposeRunners: True WorkDirectory: /root/sandbox5e64cca5 ImageRuntime Version: 4.0.30319 ImageRequiresX86: False ImageRequiresDefaultAppDomainAssembly Resolver: False NumberOfTestWorkers: 2 Test Run Summary Overall result: Failed Test Count: 1, Passed: 0, Failed: 1, Warnings: 0, Inconclusive: 0, Skipped: 0 Failed Tests Failures: 1, Errors: 0, Invalid: 0 Start time: 2022-07-05 18:45:25Z End time: 2022-07-05 18:45:26Z Duration: 1.034 seconds Test Contents [TestFixture] public class AverageArrayTest { [Test] public void Average Test() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); double [] array = {3, 4, 5, 6, 7, 8); Averages.Average(array); string expected="345678 -- Average is 5.5"; Assert.AreEqual (expected, sw.ToString().Trim(), "Expected the average of 3, 4, 5, 6, 7, and 8 to be 5.5");
I need help with getting the solution to this C# Programming Assignment. Although the code that I wrote in the first pic
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am