R
Rechtfertigung
Guest
I have a function that takes in dummy data that is randomly generated and based off the numbers it calculates the average. However I called the method in a for loop and every time the method prints to the screen, it prints the same average for every iteration of the for loop. Since the method is being called again shouldn't the return statement return a different value?
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine($"Your average test score is: {CalcAverage(RandomTestScores())}" + "\n");
}
}
static decimal CalcAverage(params decimal[] TestScores)
{
decimal AverageTestScore = default;
decimal MeanTestScore = default;
for (int i = 0; i < TestScores.Length; i++)
{
MeanTestScore += TestScores;
}
AverageTestScore = Math.Round(MeanTestScore / TestScores.Length,2);
return AverageTestScore;
}
static decimal[] RandomTestScores()
{
Random DummyData = new Random();
decimal[] TestScores = new decimal[100];
for (int i = 0; i < TestScores.Length; i++)
{
TestScores = DummyData.Next(65, 110);
}
return TestScores;
};
Recht
Continue reading...
static void Main(string[] args)
{
for (int i = 0; i < 10; i++)
{
Console.WriteLine($"Your average test score is: {CalcAverage(RandomTestScores())}" + "\n");
}
}
static decimal CalcAverage(params decimal[] TestScores)
{
decimal AverageTestScore = default;
decimal MeanTestScore = default;
for (int i = 0; i < TestScores.Length; i++)
{
MeanTestScore += TestScores;
}
AverageTestScore = Math.Round(MeanTestScore / TestScores.Length,2);
return AverageTestScore;
}
static decimal[] RandomTestScores()
{
Random DummyData = new Random();
decimal[] TestScores = new decimal[100];
for (int i = 0; i < TestScores.Length; i++)
{
TestScores = DummyData.Next(65, 110);
}
return TestScores;
};
Recht
Continue reading...