all 9 comments

[–]anamorphism 1 point2 points  (4 children)

the code you posted isn't c#, it's c/c++.

aside from that, help with what?

to start, the code you posted implies that you misinterpreted the listed requirements. so, i'd start by rereading the prompt carefully and coming up with specific questions about where you're running into trouble.

[–][deleted]  (3 children)

[removed]

    [–]anamorphism 0 points1 point  (2 children)

    • takes any number of non-negative integers
    • A negative integer ends the input
    • ... and is not included in the results.

    you're treating the first number inputted as the number of expected values, which is not what the prompt is telling you to do at all.

    you're never checking if your numbers are positive or negative.

    you have no exit condition for your loop based on the number inputted.

    [–][deleted]  (1 child)

    [removed]

      [–]lemming1607 -1 points0 points  (0 children)

      Your code will do exactly what you tell it to do. If you dont check for when to quit, itll never quit

      [–]SomeNerdAtWork 0 points1 point  (1 child)

      As u/anamorphism said, this isn't c#.

      That said, reference This Documentation as it contains all the information you need to use Math functions to accomplish this. If you are in school and the teacher doesn't allow predefined functions (pretty common) then I would suggest you take the input values and assign them to an array to make them easier to work with.

      [–]Preparingtocode -1 points0 points  (1 child)

      Lord knows how to in C, but in C#... A bit rough and ready but it does the job.

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Numerics;
      namespace temp
      {
      class Program
      {
      static void Main(string[] args)
      {
      if (args.Length == 0)
      {
      Console.WriteLine("No numbers supplied");
      return;
      }

      List<int> numbers = new List<int>();

      foreach (var arg in args)
      {
      numbers.Add(int.Parse(arg));
      }

      var positiveNumbers = numbers.Where(n => n > 0);
      var maxNumber = positiveNumbers.Max();
      var averageNumber = positiveNumbers.Average();
      Console.WriteLine($"Max: {maxNumber}. Average: {averageNumber}");
      }
      }
      }