بإمكانك تجربة هذا الكود:
static void Main(string[] args)
{
bool isExit = false;
do
{
// Ask the user
Console.WriteLine("Do you want to enter grades?");
Console.WriteLine("Yes: Enter subject name");
Console.WriteLine("No: Enter 1");
// Check input if it is subject name (continue) or 1 (exist)
string input = Console.ReadLine();
int number;
isExit = int.TryParse(input, out number);
// Input =1, exit
if (isExit)
return;
// Continue enter grades
Console.Write("Enter students count:");
int count = int.Parse(Console.ReadLine());
int[] grades = new int[count];
int sum = 0;
for (int i = 0; i < count; i++)
{
Console.Write("Enter student " + (i + 1) + " grade:");
grades[i] = int.Parse(Console.ReadLine());
sum += grades[i];
}
Console.WriteLine("--- REPORT ---");
Console.WriteLine("Subject Name: " + input);
Console.WriteLine("Students Count: " + count);
Console.WriteLine("Average: " + (sum / count));
Console.WriteLine("---------------------------");
Console.WriteLine();
} while (!isExit);
}
بالتوفيق،،،