我正在尝试存储用户提供的值,以便计算分配的总和和平均值。我可以打印值,但不能存储它们。
我不是在寻找答案,而只是为了指导。
感谢您的回复。
public class average {
public int num;
public double avg;
public average() { } // no argument method
public average(int nums, double avgt) {
num = nums;
avg = avgt;
}
public int Num {
get { return num; } // used to get the contents from the main()
set { num = value; }
}
public double Avg {
get { return avg; }
set { avg = value; }
}
public void print_info() { // prints the final results of code
// Cannot get the values to store properly
Console.WriteLine("The average is {0}, the sum of 10 numbers is {1}", (avg/10),num);
Console.WriteLine("Press any key to continue . . .");
Console.ReadLine();
}
{class assignment1 // wrapper class for main
static void Main(string[] args) {
int num0;
int val;
int nums = 0;
double avgt = 0.0;
average num1 = new average(nums, avgt);
for (val = 0; val < 10; val++) { // loop for user input
Console.Write("Enter an integer value: ");
num0 = Convert.ToInt32(Console.ReadLine());
}
num1.print_info(); // calls print_info() method
}
}
}