Jump to content

What Am I doing wrong? DisplayMybelowAverage Is the Problem:

Aaaaaaaaa

This is my code:

 

double[] scoresArray = new double[100];
            string[] playersArray = new string[100];
            char reloop = 'Y';
            int count = 0;
 
            do
            {
                double averageScore = 0;
                double belowAverage = 0;
                int numbers = 0;
 
                InputData(ref scoresArray, ref playersArray, ref count);
                DisplayPlayerData(ref scoresArray, ref playersArray, ref count);
                CalculateAverageScore(ref scoresArray, ref playersArray, ref count);
                Console.ReadLine();
                DisplayBelowAverage(ref scoresArray, ref playersArray, ref count);
                reloop = Convert.ToChar(Console.ReadLine());
                reloop = char.ToUpper(reloop);
            } while (reloop != 'Y');
        }
        
        
 
      
 
        static void InputData(ref double[] scoresArray, ref string[] playersArray, ref int count)
        {
            while (playersArray.Length <= 100)
            {
                Console.Write("Please enter the player's name: " + "((Q to Quit)) ");
                playersArray[count] = Console.ReadLine();
                if (playersArray[count] == "Q" || playersArray[count] == "q")
                {
                    break;
                }
                Console.Write("Please enter " + playersArray[count] + " scores: ");
                scoresArray[count] = Convert.ToDouble(Console.ReadLine());
                count++;
            }
        }
 
        static void DisplayPlayerData(ref double[] scoresArray, ref string[] playersArray, ref int count)
        {
            Console.WriteLine("Player            Score");
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("{0,-15}   {1,-6}", playersArray, scoresArray);
            }
        }
 
        static void CalculateAverageScore(ref double[] scoresArray, ref string[] playersArray, ref int count)
        {
            int total = 0;
            double average = 0;
            {
                foreach (int s in scoresArray)
                    total += s;
                average = total / scoresArray.Length;
                Console.Write("Average score is : ", average);
                Console.ReadLine();
            }
        }
 
        static void DisplayBelowAverage(ref double[] scoresArray, ref string[] playersArray, ref int count)
        {
 
            Console.Write("Players who score below average: ");
            Console.Write("Name     Score");
        Console.Read();
 
        foreach (int val in scoresArray)
        {
            if (val <average)
            {
                Console.WriteLine(val);
 
 
 
 
This is the question
 
 Write a program to determine statistics for a video game tournament. The user will input names and scores of all tournament players. The program will calculate the average score and display the players who scored below average.
 
The program will implement these functions:
Main(): Declares variables for the number of players and average score, and two arrays of size 100: one to store player names and the other to store their respective scores. Calls the following functions in sequence, passing necessary parameters by reference:
InputData( ): Gets player names and scores from the user and stores them into the two arrays for an unknown number of players up to 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.
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): Dave
 
Enter score for Dave: 8219
 
Enter Player Name (Q to quit): Pat
 
Enter score for Pat: 3217
 
Enter Player Name (Q to quit): Q
 
Name Score
Bob 3245
Sue 1098
Dave 8219
Pat 3217
Average Score: 3944.75
Players who scored below average
 
Name Score
Bob 3245
Sue 1098
Pat 3217
Press any key to continue . . .
 
 
Main Function
Declare player and score arrays, and variables for number of players and average score.
Call the InputData( ) function, passing arrays and number of players variable by reference
Call the DisplayPlayerData( ) function, passing arrays and number of players variable by reference
Call the CalculateAverageScore( ) function, passing arrays and number of players by reference. Store returned value in average variable.
Display the average score
Call the DisplayBelowAverage( ) function, passing arrays and number of players variable by reference, passing average variable by value
 
InputData function
Loop while the number of players is less than the length of the array
Prompt for the player's name
If the user entered Q, break out of the loop
Prompt the user for the player's score
Add 1 to the number of players
 
DisplayPlayerData function
Loop to display the name and score of each player
 
CalculateAverageScore function
Loop to add up the scores
Divide by the number of players to calculate the average score
Return the average score to main
 
DisplayBelowAverage function
Loop to display the names and scores of all players who scored below the average score

 

Link to comment
Share on other sites

Link to post
Share on other sites

What you're doing wrong... let's start off with not using pastebin

Link to comment
Share on other sites

Link to post
Share on other sites

What you're doing wrong... let's start off with not using pastebin

 

I didn't use pastebin though. This is an assignment that I need help on. So wtf are you talking about?

Link to comment
Share on other sites

Link to post
Share on other sites

I didn't use pastebin though. This is an assignment that I need help on. So wtf are you talking about?

 

Put your code in pastebin.com then link that so its easier to read. I don't know much about this, but if you use pastebin I'm sure someone who does will be much more likely/willing to help.

 

Link to comment
Share on other sites

Link to post
Share on other sites

I didn't use pastebin though. This is an assignment that I need help on. So wtf are you talking about?

 

 

Put your code in pastebin.com then link that so its easier to read. I don't know much about this, but if you use pastebin I'm sure someone who does will be much more likely/willing to help.

 

 

Or use code tags:

[code][/code]
Link to comment
Share on other sites

Link to post
Share on other sites

You didn't even say what its NOT doing.. jsut pasted the code and said help me. 

I am whatever I am. 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

You didn't even say what its NOT doing.. jsut pasted the code and said help me. 

When i try to run it in Visual Studio, the part where is says display below average, name and score nothing comes up. It does not process at all. That is my problem just the last part nothing else. 

Link to comment
Share on other sites

Link to post
Share on other sites

could you either use code tags or pastebin? Its easier to read. 

I am whatever I am. 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Hey this looks very similar to my C++ assignment when I was at Devry lol ofcource it was not in C#.

Well for one why not do what others suggested and paste it at pastebin or pastie, I would also like to suggest pasting a proper/complete version of your code. Your current one is missing a lot.
(Start from namespace and copy to the end, you are also missing a few brackets at the end)

 

Things to notice:

 

Why are averageScore, belowAverage, and numbers never used? (you just assigned them and left them there to die lol)

Is it using the loop correctly? (exiting the application through "Q", Hint: no its not)
Why is there a random Console.ReadLine() in the loop?

Why is your calculateAverageScore function void if it's supposed to return a value?

 

Besides that at first glance you need to fix your functions.

Click Here : http://pastebin.com/g4rjauWR

Link to comment
Share on other sites

Link to post
Share on other sites

   

foreach (int val in scoresArray)

you are using int there, but the scoresArray is a double array

Ryzen 7 5800X     Corsair H115i Platinum     ASUS ROG Crosshair VIII Hero (Wi-Fi)     G.Skill Trident Z 3600CL16 (@3800MHzCL16 and other tweaked timings)     

MSI RTX 3080 Gaming X Trio    Corsair HX850     WD Black SN850 1TB     Samsung 970 EVO Plus 1TB     Samsung 840 EVO 500GB     Acer XB271HU 27" 1440p 165hz G-Sync     ASUS ProArt PA278QV     LG C8 55"     Phanteks Enthoo Evolv X Glass     Logitech G915      Logitech MX Vertical      Steelseries Arctis 7 Wireless 2019      Windows 10 Pro x64

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×