## Practice Exercises C# Sharp

Learn to program with performing exercises C# Sharp

# Array of struct and menu - Practice Exercises C# Sharp

## Source Code:

``````using System;
class Program
{
struct points
{
public byte x;
public byte y;
}
static void Main(string[] args)
{
points[] p = new points[1000];
bool Finish = false;
int countArray = 0;
int TotalX = 0;
int TotalY = 0;
do
{
Console.WriteLine("2.Display all the entered points");
Console.WriteLine("3.Calculate (and display) the average values for x and y");
Console.WriteLine("0.Exit the program");
Console.Write("Enter a number: ");
switch (respuesta)
{
case 1:
Console.WriteLine();
Console.Write("Enter a number for point x: ");
TotalX += p[countArray].x;
Console.WriteLine();
Console.Write("Enter a number for point y: ");
TotalY += p[countArray].y;
Console.WriteLine();
countArray++;
break;
case 2:
if (countArray > 0)
{
for (int i = 0; i < countArray; i++)
{
Console.WriteLine("Valor x{0}: {1}", i + 1, p[i].x);
Console.WriteLine("Valor y{0}: {1}", i + 1, p[i].y);
}
}
else
Console.WriteLine("No hay datos");
break;
case 3:
if (countArray > 0)
{
Console.WriteLine("Average x: {0}", TotalX / countArray);
Console.WriteLine("Average y: {0}", TotalY / countArray);
}
else
Console.WriteLine("No hay datos");
break;
case 0:
Finish = true;
break;
default:
break;
}
}
while (!Finish);
}
}``````
Exercisey 4.10