I'm being all spacey and tired right now on this homework assignment. The issue I'm having is that I cannot seem to call the function/method to the Main method so it can be executed. For some reason the array won't pass. I have to pass the arrays by reference (which I don't seem to be having any issues with) and the average score by value. Any assistance would be greatly appreciated.
Edit: So I appear to have fixed it..kinda. But I am having an issue with the last function; DisplayBelowAverage.
I am receiving 2 errors: Argument1: Cannot convert from 'refString[] to 'ref string' and The best overloaded method match for Lab5_exA.Program.DisplayBelowAverage(ref string, ref double[],ref double, ref int)' has some invalid arguments.
I cannot seem to find where the issue is occurring. It is referring to my array: playerName when I select the errors but I can't see an issue anywhere besides maybe the fact that "ref string" in the first error doesn't have the array symbols "[]" as the other array displays.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab5_exA
{
class Program
{
public static double InputData(ref string[] playerName, ref double[] playerScore, ref int players, ref double totalScore)
{
do
{
Console.Write("Enter the player name or type 'Q' or 'q' to quit.."); //get player name
playerName[players] = Console.ReadLine();
if (playerName[players] == "Q" || playerName[players] == "q") //checks for exit value
{
break;
}
Console.WriteLine("Enter the player's score.."); //get player score
playerScore[players] = Convert.ToDouble(Console.ReadLine());
totalScore += playerScore[players];
players++; //establish size of array
} while (true);
return 0;
}
public static double DisplayPlayerData(ref string[] playerName, ref double[] playerScore, ref int players)
{
for (int w = 0; w < players; w++)
{
Console.WriteLine("Player: " + playerName[w] + "\t" + "Score: " + playerScore[w]);
}
return 0;
}
public static double CalculateAverageScore(ref int players, ref double totalScore, ref double averageScore)
{
averageScore = totalScore / players;
return averageScore;
}
public static double DisplayBelowAverage(ref string playerName, ref double[] playerScore, ref double averageScore, ref int players)
{
int z = 0;
Console.WriteLine("Average Score: " + averageScore);
Console.WriteLine("The following players received a score below the average score..");
Console.WriteLine("Name \t Score");
Console.WriteLine("---- \t ----");
while (z < players)
{
int y = 0;
if (playerScore[y] < averageScore)
{
Console.WriteLine(playerName[y] + "\t" + playerScore[y]);
}
}
return 0;
}
static void Main(string[] args)
{
string[] playerName = new string [100];
double[] playerScore = new double [100];
int players = 0;
double averageScore = 0;
double totalScore = 0;
InputData(ref playerName, ref playerScore, ref players, ref totalScore);
DisplayPlayerData(ref playerName, ref playerScore, ref players);
CalculateAverageScore(ref players, ref totalScore, ref averageScore);
DisplayBelowAverage(ref playerName, ref playerScore, ref averageScore, ref players);
Console.Read();
}
}
}
[]beforeplayerNamein the call toInputData. The other arrays you're passing don't have it.. why is that one special? Also - not sure why you're being asked to specifically pass them by reference.. you don't seem to be re-assigning the arrays in the methods (that I can see).. so there's no need.refeverywhere?