Avatar of Michael Reeve
Michael Reeve
Flag for United States of America

asked on 

Help with code

Problem
I want to be upfront this is homework assignment that I am struggling through this week (partly due to our first child being born a couple days ago). I have displayed code template (thanks to Idle_Mind for his assistance). Need to see if I am on the right track with my first method main(). I posted the details of the assignment again (originally found under another question) so it can be understood my desired outcome. I would greatly appreciate any help in understanding how to achieve the output. Thank you very much!

Details
I am trying to create a scoring system where the user will input names and scores of all players. The program will calculate the average score and display all the players who scored below average.  

Sample Output
Enter Player Name (Q to quit): Bob

Enter score for Bob: 3245

Enter Player Name (Q to quit): Sue

Enter score for Sue: 1098
Enter Player Name (Q to quit): Q

Name     Score

Bob        3245

Sue        1098
Average Score: 3944.75

Players who scored below average

Name     Score

Bob        3245
Sue        1098

Variables
My variables are:
 InputData( ): Requests the user to input the player names and scores from the user and stores them into the two arrays for an unknown number of players <= 100.  
DisplayPlayerData(): Displays each player's name and score.
CalculateAverageScore( ): Calculates the average score and returns it by value.  
DisplayBelowAverage( ): Displays the names and scores of players who scored below average.

Thank you very much in advance!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {

        static string[] playerNameAr = new string[100];
        static double[] scoreAr = new double[100];

        public static void Main(string[] args)
        {
            int numPlayers = InputData();
            int scoreCnt;
            string inValue;
            DisplayPlayerData(numPlayers);
            double averageScore = CalculateAverageScore(numPlayers);
            Console.WriteLine("\nAverage Score: {0:F}", averageScore);
            DisplayBelowAverage(numPlayers, averageScore);

            Console.WriteLine("Enter Score{0}: " + "(Press Q to exit)", scoreCnt + 1);
            inValue = Console.ReadLine();

        }

        public static int InputData()
        {
            // do while name isn't "Q", store name/score and increment counter
            // return the counter value

            While(inValue != "Q")
            {
                scoreAr[scoreCnt] = Convert.ToInt32(inValue);
                ++scoreCnt;
                Conscole.Write("Enter score {0}: " +  "(Q to exit)", scoreCnt + 1);
                inValue = Console.ReadLine();
            }
            Console.WriteLine("The number of scores: " + scoreCnt);
        }

        public static void DisplayPlayerData(int numPlayers)
        {
            // iterate over arrays up to "numPlayers" and output
        }

        public static double CalculateAverageScore(int numPlayers)
        {
            // iterate over array up to "numPlayers" and keep running total, return average


        }

        public static void DisplayBelowAverage(int numPlayers, double avg)
        {
            //iterate over array up to "numPlayers" and output those less than the average
        }

    }
}

Open in new window

C#

Avatar of undefined
Last Comment
Dmitry G

8/22/2022 - Mon