我正在尝试创建一个程序,该程序使用方法和数组来获取用户输入并显示 min、max、ave 和 total。我创建了从用户输入返回最小值、最大值、总计和平均值的方法。该代码让我获得用户输入但不会显示。我做错了什么?这就是我所拥有的。
class Program
{
const int SIZE = 6;
static void Main(string[] args)
{
double min = 0.0;
double max = 0.0;
double ave = 0.0;
double total = 0.0;
double[] numbers = new double[SIZE];
getInput(numbers);
calcmin(numbers, ref min);
calcmax(numbers, ref max);
calcTotal(numbers, ref total);
calcave(numbers, ref ave, ref total);
printResult(numbers, ref min, ref max, ref ave, ref total);
}//v
static void calcave(double[] numbers, ref double ave, ref double total)
{
int sub = 0;
while (sub < numbers.Length)
{
ave = total / numbers.Length;
}
sub++;
}//end while
static void calcTotal(double[] numbers, ref double total)
{
int sub = 0;
while (sub < numbers.Length)
{
total = numbers[sub] + total ;
}
sub++
}//end while
static void calcmax(double[] numbers, ref double max)
{
int sub = 0;
max = numbers[0];
while (sub < numbers.Length)
if (numbers[sub] > max)
{
numbers[sub] = max;
}//end if
sub++;
}//end while
static void calcmin(double[] numbers, ref double min)
{
int sub = 0;
min = numbers[0];
while (sub < numbers.Length)
if (numbers[sub] < min)
{
numbers[sub] = min;
}//end if
sub++;
}//end while
static void getInput(double[] numbers)
{
int sub = 0;
for (sub = 0; sub < numbers.Length; sub++)
{
Console.WriteLine("Enter number {0}",sub + 1);
while (!double.TryParse(Console.ReadLine(), out numbers[sub]))
Console.WriteLine("Please try again.");
}//End write lines
}//end while
static void printResult(double[] numbers, ref double min, ref double max, ref double ave, ref double total)
{
Console.WriteLine("The smallest number is {0}.", min);
Console.WriteLine("the largest number is {0}.", max);
Console.WriteLine("the total is {0}.", total);
Console.WriteLine("The average is {0}.", ave);
}//end write lines for out put of Minimum, Maximum, Total, and Average.
}
}
}