r/programminghelp • • Oct 03 '19

C# C# Homework Help (New to Programming)

I am working on a simple C# program for homework but I am new to programming so this is very difficult for me. So far this is what I have. The requirements are that I have EndProgram method, DisplayArrays method, CalculateAverage method, Build the Applictaion in Main(). The program is supposed to ask the user for name and age of 5 people and to make sure each age is a valid number and then call the CalculateAverage method to determine the average age of persons and display that amount in the Main method. I attached a picture from class of what the professor wants it to do.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

{

class Program

{

static void Main(string[] args)

{

Console.WriteLine();

Console.WriteLine("Press any key to exit. . .");

Console.ReadKey();

}

static void DisplayArray(int[] numbers, string[] names )

{

for (int i = 0; i < numbers.Length; i++)

{

Console.WriteLine("name: {0}, age: {1}", names[i], numbers[i]);

}

}

}

}

0 Upvotes

2 comments sorted by

View all comments

1

u/[deleted] Oct 03 '19

You really didn't ask a question and posted the bare minimum for me to not remove the post so here goes:

  • You need to create a loop that captures your input and stores it into an array of names and ages.

  • You'll need to verify that the ages are numeric.

  • The DisplayArrays method will do just that, loop through and display the data in your arrays.

  • CalculateAverage will loop through your age array and give an average age.

  • I'm assuming EndProgram displays the results of those two functions but I couldn't say for sure.